mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2025-12-06 00:36:10 +00:00
Update scalar to support multi-sources
This commit is contained in:
12
bun.lock
12
bun.lock
@@ -4,8 +4,8 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "@elysiajs/swagger",
|
"name": "@elysiajs/swagger",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@scalar/themes": "^0.9.52",
|
"@scalar/themes": "^0.9.81",
|
||||||
"@scalar/types": "^0.0.12",
|
"@scalar/types": "^0.1.3",
|
||||||
"openapi-types": "^12.1.3",
|
"openapi-types": "^12.1.3",
|
||||||
"pathe": "^1.1.2",
|
"pathe": "^1.1.2",
|
||||||
},
|
},
|
||||||
@@ -159,11 +159,11 @@
|
|||||||
|
|
||||||
"@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.40.1", "", { "os": "win32", "cpu": "x64" }, "sha512-ECyOuDeH3C1I8jH2MK1RtBJW+YPMvSfT0a5NN0nHfQYnDSJ6tUiZH3gzwVP5/Kfh/+Tt7tpWVF9LXNTnhTJ3kA=="],
|
"@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.40.1", "", { "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/themes@0.9.86", "", { "dependencies": { "@scalar/types": "0.1.7" } }, "sha512-QUHo9g5oSWi+0Lm1vJY9TaMZRau8LHg+vte7q5BVTBnu6NuQfigCaN+ouQ73FqIVd96TwMO6Db+dilK1B+9row=="],
|
"@scalar/themes": ["@scalar/themes@0.9.86", "", { "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/typebox@0.34.33", "", {}, "sha512-5HAV9exOMcXRUxo+9iYB5n09XxzCXnfy4VTNW4xnDv+FgjzAGY989C28BIdljKqmF+ZltUwujE3aossvcVtq6g=="],
|
"@sinclair/typebox": ["@sinclair/typebox@0.34.33", "", {}, "sha512-5HAV9exOMcXRUxo+9iYB5n09XxzCXnfy4VTNW4xnDv+FgjzAGY989C28BIdljKqmF+ZltUwujE3aossvcVtq6g=="],
|
||||||
|
|
||||||
@@ -475,8 +475,6 @@
|
|||||||
|
|
||||||
"@isaacs/cliui/strip-ansi": ["strip-ansi@7.1.0", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ=="],
|
"@isaacs/cliui/strip-ansi": ["strip-ansi@7.1.0", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ=="],
|
||||||
|
|
||||||
"@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=="],
|
|
||||||
|
|
||||||
"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=="],
|
"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=="],
|
||||||
|
|
||||||
"glob/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
|
"glob/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="],
|
||||||
@@ -497,8 +495,6 @@
|
|||||||
|
|
||||||
"@isaacs/cliui/strip-ansi/ansi-regex": ["ansi-regex@6.1.0", "", {}, "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA=="],
|
"@isaacs/cliui/strip-ansi/ansi-regex": ["ansi-regex@6.1.0", "", {}, "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA=="],
|
||||||
|
|
||||||
"@scalar/themes/@scalar/types/@scalar/openapi-types": ["@scalar/openapi-types@0.2.0", "", { "dependencies": { "zod": "^3.23.8" } }, "sha512-waiKk12cRCqyUCWTOX0K1WEVX46+hVUK+zRPzAahDJ7G0TApvbNkuy5wx7aoUyEk++HHde0XuQnshXnt8jsddA=="],
|
|
||||||
|
|
||||||
"eslint/ajv/json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
|
"eslint/ajv/json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
|
||||||
|
|
||||||
"glob/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="],
|
"glob/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="],
|
||||||
|
|||||||
@@ -68,8 +68,8 @@
|
|||||||
"typescript": "^5.5.3"
|
"typescript": "^5.5.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@scalar/themes": "^0.9.52",
|
"@scalar/themes": "^0.9.81",
|
||||||
"@scalar/types": "^0.0.12",
|
"@scalar/types": "^0.1.3",
|
||||||
"openapi-types": "^12.1.3",
|
"openapi-types": "^12.1.3",
|
||||||
"pathe": "^1.1.2"
|
"pathe": "^1.1.2"
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/index.ts
12
src/index.ts
@@ -7,7 +7,7 @@ import { ScalarRender } from './scalar'
|
|||||||
import { filterPaths, registerSchemaPath } from './utils'
|
import { filterPaths, registerSchemaPath } from './utils'
|
||||||
|
|
||||||
import type { OpenAPIV3 } from 'openapi-types'
|
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'
|
import type { ElysiaSwaggerConfig } from './types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +45,6 @@ export const swagger = <Path extends string = '/swagger'>({
|
|||||||
...documentation.info
|
...documentation.info
|
||||||
}
|
}
|
||||||
|
|
||||||
const relativePath = path.startsWith('/') ? path.slice(1) : path
|
|
||||||
|
|
||||||
const app = new Elysia({ name: '@elysiajs/swagger' })
|
const app = new Elysia({ name: '@elysiajs/swagger' })
|
||||||
|
|
||||||
const page = new Response(
|
const page = new Response(
|
||||||
@@ -70,15 +68,11 @@ export const swagger = <Path extends string = '/swagger'>({
|
|||||||
info,
|
info,
|
||||||
scalarVersion,
|
scalarVersion,
|
||||||
{
|
{
|
||||||
spec: {
|
sources: [{url: specPath}],
|
||||||
...scalarConfig.spec,
|
|
||||||
url: specPath
|
|
||||||
},
|
|
||||||
...scalarConfig,
|
...scalarConfig,
|
||||||
// so we can showcase the elysia theme
|
// so we can showcase the elysia theme
|
||||||
// @ts-expect-error
|
|
||||||
_integration: 'elysiajs'
|
_integration: 'elysiajs'
|
||||||
} satisfies ReferenceConfiguration,
|
} satisfies Partial<ApiReferenceConfigurationWithSources>,
|
||||||
scalarCDN
|
scalarCDN
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { elysiajsTheme } from '@scalar/themes'
|
import { elysiajsTheme } from '@scalar/themes'
|
||||||
import type { OpenAPIV3 } from 'openapi-types'
|
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 = (
|
export const ScalarRender = (
|
||||||
info: OpenAPIV3.InfoObject,
|
info: OpenAPIV3.InfoObject,
|
||||||
version: string,
|
version: string,
|
||||||
config: ReferenceConfiguration,
|
config: Partial<ApiReferenceConfigurationWithSources>,
|
||||||
cdn: string
|
cdn: string
|
||||||
) => `<!doctype html>
|
) => `<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
@@ -33,16 +33,16 @@ export const ScalarRender = (
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script
|
<div id="app"></div>
|
||||||
id="api-reference"
|
|
||||||
data-url="${config.spec?.url}"
|
|
||||||
data-configuration='${JSON.stringify(config)}'
|
|
||||||
>
|
|
||||||
</script>
|
|
||||||
<script src="${
|
<script src="${
|
||||||
cdn
|
cdn
|
||||||
? cdn
|
? cdn
|
||||||
: `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`
|
: `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`
|
||||||
}" crossorigin></script>
|
}" crossorigin></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
Scalar.createApiReference('#app', ${JSON.stringify(config)})
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { OpenAPIV3 } from 'openapi-types'
|
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'
|
import type { SwaggerUIOptions } from './swagger/types'
|
||||||
|
|
||||||
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
|
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
|
||||||
@@ -46,7 +46,7 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
|
|||||||
*'
|
*'
|
||||||
* @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md
|
* @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md
|
||||||
*/
|
*/
|
||||||
scalarConfig?: ReferenceConfiguration
|
scalarConfig?: Partial<ApiReferenceConfigurationWithSources>
|
||||||
/**
|
/**
|
||||||
* Version to use for swagger cdn bundle
|
* Version to use for swagger cdn bundle
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user