mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2026-05-30 12:48:32 +00:00
feat: use latest cdn and add optional override for cdn
This commit is contained in:
+5
-3
@@ -19,7 +19,8 @@ export const swagger =
|
||||
<Path extends string = '/swagger'>(
|
||||
{
|
||||
provider = 'scalar',
|
||||
scalarVersion = '1.13.0',
|
||||
scalarVersion = 'latest',
|
||||
scalarCDN = '',
|
||||
scalarConfig = {},
|
||||
documentation = {},
|
||||
version = '5.9.0',
|
||||
@@ -32,7 +33,8 @@ export const swagger =
|
||||
excludeMethods = ['OPTIONS']
|
||||
}: ElysiaSwaggerConfig<Path> = {
|
||||
provider: 'scalar',
|
||||
scalarVersion: '1.12.5',
|
||||
scalarVersion: 'latest',
|
||||
scalarCDN: '',
|
||||
scalarConfig: {},
|
||||
documentation: {},
|
||||
version: '5.9.0',
|
||||
@@ -93,7 +95,7 @@ export const swagger =
|
||||
stringifiedSwaggerOptions,
|
||||
autoDarkMode
|
||||
)
|
||||
: ScalarRender(scalarVersion, scalarConfiguration),
|
||||
: ScalarRender(scalarVersion, scalarConfiguration, scalarCDN),
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=utf8'
|
||||
|
||||
+28
-24
@@ -1,27 +1,31 @@
|
||||
import scalarElysiaTheme from './theme'
|
||||
import type { ReferenceConfiguration } from './types'
|
||||
|
||||
export const ScalarRender = (version: string, config: ReferenceConfiguration) => `<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>API Reference</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1" />
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
${config.customCss ?? scalarElysiaTheme}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script
|
||||
id="api-reference"
|
||||
data-url="${config.spec?.url}"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js"></script>
|
||||
</body>
|
||||
</html>`
|
||||
export const ScalarRender = (version: string, config: ReferenceConfiguration, scalarCDN: string) => {
|
||||
const overrideScalarCDN = scalarCDN ? scalarCDN : `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`
|
||||
|
||||
return `<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>API Reference</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1" />
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
${config.customCss ?? scalarElysiaTheme}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script
|
||||
id="api-reference"
|
||||
data-url="${config.spec?.url}"></script>
|
||||
<script src="${overrideScalarCDN}"></script>
|
||||
</body>
|
||||
</html>`
|
||||
}
|
||||
+9
-3
@@ -24,14 +24,20 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
|
||||
/**
|
||||
* Version to use for Scalar cdn bundle
|
||||
*
|
||||
* @default '1.12.5'
|
||||
* @default 'latest'
|
||||
* @see https://github.com/scalar/scalar
|
||||
*/
|
||||
scalarVersion?: string
|
||||
/**
|
||||
* Scalar configuration to customize scalar
|
||||
* Optional override to specifying the path for the Scalar bundle
|
||||
*
|
||||
* @default '1.12.5'
|
||||
* @default ''
|
||||
* @see https://github.com/scalar/scalar
|
||||
*/
|
||||
scalarCDN?: string
|
||||
/**
|
||||
* Scalar configuration to customize scalar
|
||||
*'
|
||||
* @see https://github.com/scalar/scalar
|
||||
*/
|
||||
scalarConfig?: ReferenceConfiguration
|
||||
|
||||
Reference in New Issue
Block a user