Skip to content

Commit 56e1ba3

Browse files
committed
fix: 🐛 prevent failed to fetch spec from URL error
1 parent 55b86f0 commit 56e1ba3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ export const swagger = async <Path extends string = '/swagger'>(
6262

6363
const relativePath = path.startsWith('/') ? path.slice(1) : path
6464

65+
const openAPISpecUrl = relativePath === '' ? `/json` : `/${relativePath}/json`
66+
6567
const app = new Elysia({ name: '@elysiajs/swagger' })
6668

6769
app.get(path, function documentation() {
6870
const combinedSwaggerOptions = {
69-
url: `/${relativePath}/json`,
71+
url: openAPISpecUrl,
7072
dom_id: '#swagger-ui',
7173
...swaggerOptions
7274
}
@@ -83,7 +85,7 @@ export const swagger = async <Path extends string = '/swagger'>(
8385
const scalarConfiguration: ReferenceConfiguration = {
8486
spec: {
8587
...scalarConfig.spec,
86-
url: `/${relativePath}/json`
88+
url: openAPISpecUrl
8789
},
8890
...scalarConfig
8991
}

0 commit comments

Comments
 (0)