feat: use latest cdn and add optional override for cdn

This commit is contained in:
marclave
2024-01-22 14:16:58 -08:00
parent 9c24a69390
commit 702bf43ef9
3 changed files with 42 additions and 30 deletions
+5 -3
View File
@@ -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
View File
@@ -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
View File
@@ -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