fix: 🐛 prevent failed to fetch spec from URL error

This commit is contained in:
jimmy-guzman
2024-10-13 00:58:34 -05:00
parent 55b86f0335
commit 56e1ba3561

View File

@@ -62,11 +62,13 @@ export const swagger = async <Path extends string = '/swagger'>(
const relativePath = path.startsWith('/') ? path.slice(1) : path const relativePath = path.startsWith('/') ? path.slice(1) : path
const openAPISpecUrl = relativePath === '' ? `/json` : `/${relativePath}/json`
const app = new Elysia({ name: '@elysiajs/swagger' }) const app = new Elysia({ name: '@elysiajs/swagger' })
app.get(path, function documentation() { app.get(path, function documentation() {
const combinedSwaggerOptions = { const combinedSwaggerOptions = {
url: `/${relativePath}/json`, url: openAPISpecUrl,
dom_id: '#swagger-ui', dom_id: '#swagger-ui',
...swaggerOptions ...swaggerOptions
} }
@@ -83,7 +85,7 @@ export const swagger = async <Path extends string = '/swagger'>(
const scalarConfiguration: ReferenceConfiguration = { const scalarConfiguration: ReferenceConfiguration = {
spec: { spec: {
...scalarConfig.spec, ...scalarConfig.spec,
url: `/${relativePath}/json` url: openAPISpecUrl
}, },
...scalarConfig ...scalarConfig
} }