Skip to content

Commit 95e3b57

Browse files
committed
Update scalar to support multi-sources
1 parent 65b20fc commit 95e3b57

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

bun.lockb

-415 Bytes
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"typescript": "^5.5.3"
6969
},
7070
"dependencies": {
71-
"@scalar/themes": "^0.9.52",
72-
"@scalar/types": "^0.0.12",
71+
"@scalar/themes": "^0.9.81",
72+
"@scalar/types": "^0.1.3",
7373
"openapi-types": "^12.1.3",
7474
"pathe": "^1.1.2"
7575
}

src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ScalarRender } from './scalar'
77
import { filterPaths, registerSchemaPath } from './utils'
88

99
import type { OpenAPIV3 } from 'openapi-types'
10-
import type { ReferenceConfiguration } from '@scalar/types'
10+
import type { ApiReferenceConfigurationWithSources } from '@scalar/types/api-reference' with { "resolution-mode": "import" };
1111
import type { ElysiaSwaggerConfig } from './types'
1212

1313
/**
@@ -82,14 +82,11 @@ export const swagger = async <Path extends string = '/swagger'>(
8282
}
8383
)
8484

85-
const scalarConfiguration: ReferenceConfiguration = {
86-
spec: {
87-
...scalarConfig.spec,
88-
url: `${new URL(request.url).pathname.replace(/\/$/, "")}/json`
89-
},
85+
const scalarConfiguration: Partial<ApiReferenceConfigurationWithSources> = {
86+
sources: [{url: `${new URL(request.url).pathname.replace(/\/$/, "")}/json` }],
87+
// allow scalarConfig to override sources if they want to define more than one
9088
...scalarConfig,
9189
// so we can showcase the elysia theme
92-
// @ts-expect-error
9390
_integration: 'elysiajs'
9491
}
9592

src/scalar/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { elysiajsTheme } from '@scalar/themes'
22
import type { OpenAPIV3 } from 'openapi-types'
3-
import type { ReferenceConfiguration } from '@scalar/types'
3+
import type { ApiReferenceConfigurationWithSources } from '@scalar/types/api-reference' with { "resolution-mode": "import" };
44

55
export const ScalarRender = (
66
info: OpenAPIV3.InfoObject,
77
version: string,
8-
config: ReferenceConfiguration,
8+
config: Partial<ApiReferenceConfigurationWithSources>,
99
cdn: string
1010
) => `<!doctype html>
1111
<html>
@@ -33,16 +33,16 @@ export const ScalarRender = (
3333
</style>
3434
</head>
3535
<body>
36-
<script
37-
id="api-reference"
38-
data-url="${config.spec?.url}"
39-
data-configuration='${JSON.stringify(config)}'
40-
>
41-
</script>
36+
<div id="app"></div>
37+
4238
<script src="${
4339
cdn
4440
? cdn
4541
: `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`
4642
}" crossorigin></script>
43+
44+
<script>
45+
Scalar.createApiReference('#app', ${JSON.stringify(config)})
46+
</script>
4747
</body>
4848
</html>`

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OpenAPIV3 } from 'openapi-types'
2-
import type { ReferenceConfiguration } from '@scalar/types'
2+
import type { ApiReferenceConfigurationWithSources } from '@scalar/types/api-reference' with { "resolution-mode": "import" };
33
import type { SwaggerUIOptions } from './swagger/types'
44

55
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
@@ -46,7 +46,7 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
4646
*'
4747
* @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md
4848
*/
49-
scalarConfig?: ReferenceConfiguration
49+
scalarConfig?: Partial<ApiReferenceConfigurationWithSources>
5050
/**
5151
* Version to use for swagger cdn bundle
5252
*

0 commit comments

Comments
 (0)