Merge pull request #153 from inyourtime/fix-scalar-reference-configuration-type

feat: update scalar configuration to use `@scalar/types`
This commit is contained in:
Marc Laventure
2024-10-04 11:28:57 -07:00
committed by GitHub
9 changed files with 37 additions and 1029 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,7 +1,5 @@
import { Elysia, InternalRoute } from 'elysia' import { Elysia } from 'elysia'
import { swagger } from '../src/index' import { swagger } from '../src/index'
import { plugin } from './plugin'
import { registerSchemaPath } from '../src/utils'
const app = new Elysia() const app = new Elysia()
.use( .use(
@@ -39,6 +37,5 @@ const app = new Elysia()
} }
}) })
) )
// .use(plugin)
.get('/id/:id?', 'a') .get('/id/:id?', 'a')
.listen(3000) .listen(3000)

View File

@@ -36,11 +36,6 @@
"types": "./dist/scalar/theme.d.ts", "types": "./dist/scalar/theme.d.ts",
"import": "./dist/scalar/theme.mjs", "import": "./dist/scalar/theme.mjs",
"require": "./dist/cjs/scalar/theme.js" "require": "./dist/cjs/scalar/theme.js"
},
"./scalar/types": {
"types": "./dist/scalar/types/index.d.ts",
"import": "./dist/scalar/types/index.mjs",
"require": "./dist/cjs/scalar/types/index.js"
} }
}, },
"keywords": [ "keywords": [
@@ -66,7 +61,6 @@
}, },
"devDependencies": { "devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0", "@apidevtools/swagger-parser": "^10.1.0",
"@scalar/api-reference": "^1.25.21",
"@types/bun": "1.1.6", "@types/bun": "1.1.6",
"elysia": ">= 1.1.0-rc.2", "elysia": ">= 1.1.0-rc.2",
"eslint": "9.6.0", "eslint": "9.6.0",
@@ -74,6 +68,7 @@
"typescript": "^5.5.3" "typescript": "^5.5.3"
}, },
"dependencies": { "dependencies": {
"@scalar/types": "^0.0.12",
"openapi-types": "^12.1.3", "openapi-types": "^12.1.3",
"pathe": "^1.1.2" "pathe": "^1.1.2"
} }

View File

@@ -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/api-reference' import type { ReferenceConfiguration } from '@scalar/types'
import type { ElysiaSwaggerConfig } from './types' import type { ElysiaSwaggerConfig } from './types'
/** /**

View File

@@ -1,6 +1,6 @@
import scalarElysiaTheme from './theme' import scalarElysiaTheme from './theme'
import type { OpenAPIV3 } from 'openapi-types' import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from '@scalar/api-reference' import type { ReferenceConfiguration } from '@scalar/types'
export const ScalarRender = ( export const ScalarRender = (
info: OpenAPIV3.InfoObject, info: OpenAPIV3.InfoObject,

View File

@@ -1,12 +0,0 @@
export type SpecConfiguration = {
/** URL to a Swagger/OpenAPI file */
url?: string;
/** Swagger/Open API spec */
content?: string | Record<string, any> | (() => Record<string, any>);
/** The result of @scalar/swagger-parser */
preparsedContent?: Record<any, any>;
};
export type ReferenceLayoutType = 'modern' | 'classic';
export type ThemeId = 'alternate' | 'default' | 'moon' | 'purple' | 'solarized' | 'none';

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
import type { OpenAPIV3 } from 'openapi-types' import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from '@scalar/api-reference' import type { ReferenceConfiguration } from '@scalar/types'
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'> {
@@ -44,7 +44,7 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
/** /**
* Scalar configuration to customize scalar * Scalar configuration to customize scalar
*' *'
* @see https://github.com/scalar/scalar * @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md
*/ */
scalarConfig?: ReferenceConfiguration scalarConfig?: ReferenceConfiguration
/** /**

View File

@@ -45,7 +45,7 @@ describe('Swagger', () => {
).toBe(true) ).toBe(true)
}) })
it('follow title and description', async () => { it('follow title and description with Swagger-UI provider', async () => {
const app = new Elysia().use( const app = new Elysia().use(
swagger({ swagger({
version: '4.5.0', version: '4.5.0',
@@ -75,6 +75,36 @@ describe('Swagger', () => {
).toBe(true) ).toBe(true)
}) })
it('follow title and description with Scalar provider', async () => {
const app = new Elysia().use(
swagger({
version: '4.5.0',
provider: 'scalar',
documentation: {
info: {
title: 'Elysia Documentation',
description: 'Herrscher of Human',
version: '1.0.0'
}
}
})
)
await app.modules
const res = await app.handle(req('/swagger')).then((x) => x.text())
expect(res.includes('<title>Elysia Documentation</title>')).toBe(true)
expect(
res.includes(
`<meta
name="description"
content="Herrscher of Human"
/>`
)
).toBe(true)
})
it('use custom path', async () => { it('use custom path', async () => {
const app = new Elysia().use( const app = new Elysia().use(
swagger({ swagger({