Skip to content

Update scalar to support multi-sources #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"": {
"name": "@elysiajs/swagger",
"dependencies": {
"@scalar/themes": "^0.9.52",
"@scalar/types": "^0.0.12",
"@scalar/themes": "^0.9.81",
"@scalar/types": "^0.1.3",
"openapi-types": "^12.1.3",
"pathe": "^1.1.2",
},
Expand Down Expand Up @@ -159,11 +159,11 @@

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

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

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

"@scalar/types": ["@scalar/types@0.0.12", "", { "dependencies": { "@scalar/openapi-types": "0.1.1", "@unhead/schema": "^1.9.5" } }, "sha512-XYZ36lSEx87i4gDqopQlGCOkdIITHHEvgkuJFrXFATQs9zHARop0PN0g4RZYWj+ZpCUclOcaOjbCt8JGe22mnQ=="],
"@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=="],

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

Expand Down Expand Up @@ -475,8 +475,6 @@

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

"@scalar/themes/@scalar/types": ["@scalar/[email protected]", "", { "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=="],

"eslint/ajv": ["[email protected]", "", { "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=="],

"glob/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
Expand All @@ -497,8 +495,6 @@

"@isaacs/cliui/strip-ansi/ansi-regex": ["[email protected]", "", {}, "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA=="],

"@scalar/themes/@scalar/types/@scalar/openapi-types": ["@scalar/[email protected]", "", { "dependencies": { "zod": "^3.23.8" } }, "sha512-waiKk12cRCqyUCWTOX0K1WEVX46+hVUK+zRPzAahDJ7G0TApvbNkuy5wx7aoUyEk++HHde0XuQnshXnt8jsddA=="],

"eslint/ajv/json-schema-traverse": ["[email protected]", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],

"glob/minimatch/brace-expansion": ["[email protected]", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"typescript": "^5.5.3"
},
"dependencies": {
"@scalar/themes": "^0.9.52",
"@scalar/types": "^0.0.12",
"@scalar/themes": "^0.9.81",
"@scalar/types": "^0.1.3",
"openapi-types": "^12.1.3",
"pathe": "^1.1.2"
}
Expand Down
12 changes: 3 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ScalarRender } from './scalar'
import { filterPaths, registerSchemaPath } from './utils'

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

/**
Expand Down Expand Up @@ -45,8 +45,6 @@ export const swagger = <Path extends string = '/swagger'>({
...documentation.info
}

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

const app = new Elysia({ name: '@elysiajs/swagger' })

const page = new Response(
Expand All @@ -70,15 +68,11 @@ export const swagger = <Path extends string = '/swagger'>({
info,
scalarVersion,
{
spec: {
...scalarConfig.spec,
url: specPath
},
sources: [{url: specPath}],
...scalarConfig,
// so we can showcase the elysia theme
// @ts-expect-error
_integration: 'elysiajs'
} satisfies ReferenceConfiguration,
} satisfies Partial<ApiReferenceConfigurationWithSources>,
scalarCDN
),
{
Expand Down
16 changes: 8 additions & 8 deletions src/scalar/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { elysiajsTheme } from '@scalar/themes'
import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from '@scalar/types'
import type { ApiReferenceConfigurationWithSources } from '@scalar/types/api-reference' with { "resolution-mode": "import" };

export const ScalarRender = (
info: OpenAPIV3.InfoObject,
version: string,
config: ReferenceConfiguration,
config: Partial<ApiReferenceConfigurationWithSources>,
cdn: string
) => `<!doctype html>
<html>
Expand Down Expand Up @@ -33,16 +33,16 @@ export const ScalarRender = (
</style>
</head>
<body>
<script
id="api-reference"
data-url="${config.spec?.url}"
data-configuration='${JSON.stringify(config)}'
>
</script>
<div id="app"></div>

<script src="${
cdn
? cdn
: `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`
}" crossorigin></script>

<script>
Scalar.createApiReference('#app', ${JSON.stringify(config)})
</script>
</body>
</html>`
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from '@scalar/types'
import type { ApiReferenceConfigurationWithSources } from '@scalar/types/api-reference' with { "resolution-mode": "import" };
import type { SwaggerUIOptions } from './swagger/types'

export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
Expand Down Expand Up @@ -46,7 +46,7 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
*'
* @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md
*/
scalarConfig?: ReferenceConfiguration
scalarConfig?: Partial<ApiReferenceConfigurationWithSources>
/**
* Version to use for swagger cdn bundle
*
Expand Down