Skip to content

Commit 07adf7e

Browse files
committed
Update scalar to support multi-sources
1 parent 604db87 commit 07adf7e

File tree

5 files changed

+19
-29
lines changed

5 files changed

+19
-29
lines changed

bun.lock

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"": {
55
"name": "@elysiajs/swagger",
66
"dependencies": {
7-
"@scalar/themes": "^0.9.52",
8-
"@scalar/types": "^0.0.12",
7+
"@scalar/themes": "^0.9.81",
8+
"@scalar/types": "^0.1.3",
99
"openapi-types": "^12.1.3",
1010
"pathe": "^1.1.2",
1111
},
@@ -159,11 +159,11 @@
159159

160160
"@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.40.1", "", { "os": "win32", "cpu": "x64" }, "sha512-ECyOuDeH3C1I8jH2MK1RtBJW+YPMvSfT0a5NN0nHfQYnDSJ6tUiZH3gzwVP5/Kfh/+Tt7tpWVF9LXNTnhTJ3kA=="],
161161

162-
"@scalar/openapi-types": ["@scalar/openapi-types@0.1.1", "", {}, "sha512-NMy3QNk6ytcCoPUGJH0t4NNr36OWXgZhA3ormr3TvhX1NDgoF95wFyodGVH8xiHeUyn2/FxtETm8UBLbB5xEmg=="],
162+
"@scalar/openapi-types": ["@scalar/openapi-types@0.2.0", "", { "dependencies": { "zod": "^3.23.8" } }, "sha512-waiKk12cRCqyUCWTOX0K1WEVX46+hVUK+zRPzAahDJ7G0TApvbNkuy5wx7aoUyEk++HHde0XuQnshXnt8jsddA=="],
163163

164164
"@scalar/themes": ["@scalar/themes@0.9.86", "", { "dependencies": { "@scalar/types": "0.1.7" } }, "sha512-QUHo9g5oSWi+0Lm1vJY9TaMZRau8LHg+vte7q5BVTBnu6NuQfigCaN+ouQ73FqIVd96TwMO6Db+dilK1B+9row=="],
165165

166-
"@scalar/types": ["@scalar/types@0.0.12", "", { "dependencies": { "@scalar/openapi-types": "0.1.1", "@unhead/schema": "^1.9.5" } }, "sha512-XYZ36lSEx87i4gDqopQlGCOkdIITHHEvgkuJFrXFATQs9zHARop0PN0g4RZYWj+ZpCUclOcaOjbCt8JGe22mnQ=="],
166+
"@scalar/types": ["@scalar/types@0.1.7", "", { "dependencies": { "@scalar/openapi-types": "0.2.0", "@unhead/schema": "^1.11.11", "nanoid": "^5.1.5", "type-fest": "^4.20.0", "zod": "^3.23.8" } }, "sha512-irIDYzTQG2KLvFbuTI8k2Pz/R4JR+zUUSykVTbEMatkzMmVFnn1VzNSMlODbadycwZunbnL2tA27AXed9URVjw=="],
167167

168168
"@sinclair/typebox": ["@sinclair/typebox@0.34.33", "", {}, "sha512-5HAV9exOMcXRUxo+9iYB5n09XxzCXnfy4VTNW4xnDv+FgjzAGY989C28BIdljKqmF+ZltUwujE3aossvcVtq6g=="],
169169

@@ -475,8 +475,6 @@
475475

476476
"@isaacs/cliui/strip-ansi": ["strip-ansi@7.1.0", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ=="],
477477

478-
"@scalar/themes/@scalar/types": ["@scalar/types@0.1.7", "", { "dependencies": { "@scalar/openapi-types": "0.2.0", "@unhead/schema": "^1.11.11", "nanoid": "^5.1.5", "type-fest": "^4.20.0", "zod": "^3.23.8" } }, "sha512-irIDYzTQG2KLvFbuTI8k2Pz/R4JR+zUUSykVTbEMatkzMmVFnn1VzNSMlODbadycwZunbnL2tA27AXed9URVjw=="],
479-
480478
"eslint/ajv": ["ajv@6.12.6", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g=="],
481479

482480
"glob/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
@@ -497,8 +495,6 @@
497495

498496
"@isaacs/cliui/strip-ansi/ansi-regex": ["ansi-regex@6.1.0", "", {}, "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA=="],
499497

500-
"@scalar/themes/@scalar/types/@scalar/openapi-types": ["@scalar/openapi-types@0.2.0", "", { "dependencies": { "zod": "^3.23.8" } }, "sha512-waiKk12cRCqyUCWTOX0K1WEVX46+hVUK+zRPzAahDJ7G0TApvbNkuy5wx7aoUyEk++HHde0XuQnshXnt8jsddA=="],
501-
502498
"eslint/ajv/json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
503499

504500
"glob/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="],

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: 3 additions & 9 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
/**
@@ -45,8 +45,6 @@ export const swagger = <Path extends string = '/swagger'>({
4545
...documentation.info
4646
}
4747

48-
const relativePath = path.startsWith('/') ? path.slice(1) : path
49-
5048
const app = new Elysia({ name: '@elysiajs/swagger' })
5149

5250
const page = new Response(
@@ -70,15 +68,11 @@ export const swagger = <Path extends string = '/swagger'>({
7068
info,
7169
scalarVersion,
7270
{
73-
spec: {
74-
...scalarConfig.spec,
75-
url: specPath
76-
},
71+
sources: [{url: specPath}],
7772
...scalarConfig,
7873
// so we can showcase the elysia theme
79-
// @ts-expect-error
8074
_integration: 'elysiajs'
81-
} satisfies ReferenceConfiguration,
75+
} satisfies Partial<ApiReferenceConfigurationWithSources>,
8276
scalarCDN
8377
),
8478
{

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)