Skip to content

Commit f2b62fa

Browse files
authored
Merge pull request #154 from jimmy-guzman/fix-prevent-failed-to-fetch-spec-from-URL
2 parents ed00255 + 56e1ba3 commit f2b62fa

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
// so we can showcase the elysia theme

0 commit comments

Comments
 (0)