mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2025-12-06 00:36:10 +00:00
Merge pull request #153 from inyourtime/fix-scalar-reference-configuration-type
feat: update scalar configuration to use `@scalar/types`
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Elysia, InternalRoute } from 'elysia'
|
||||
import { Elysia } from 'elysia'
|
||||
import { swagger } from '../src/index'
|
||||
import { plugin } from './plugin'
|
||||
import { registerSchemaPath } from '../src/utils'
|
||||
|
||||
const app = new Elysia()
|
||||
.use(
|
||||
@@ -39,6 +37,5 @@ const app = new Elysia()
|
||||
}
|
||||
})
|
||||
)
|
||||
// .use(plugin)
|
||||
.get('/id/:id?', 'a')
|
||||
.listen(3000)
|
||||
|
||||
@@ -36,11 +36,6 @@
|
||||
"types": "./dist/scalar/theme.d.ts",
|
||||
"import": "./dist/scalar/theme.mjs",
|
||||
"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": [
|
||||
@@ -66,7 +61,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apidevtools/swagger-parser": "^10.1.0",
|
||||
"@scalar/api-reference": "^1.25.21",
|
||||
"@types/bun": "1.1.6",
|
||||
"elysia": ">= 1.1.0-rc.2",
|
||||
"eslint": "9.6.0",
|
||||
@@ -74,6 +68,7 @@
|
||||
"typescript": "^5.5.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@scalar/types": "^0.0.12",
|
||||
"openapi-types": "^12.1.3",
|
||||
"pathe": "^1.1.2"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ScalarRender } from './scalar'
|
||||
import { filterPaths, registerSchemaPath } from './utils'
|
||||
|
||||
import type { OpenAPIV3 } from 'openapi-types'
|
||||
import type { ReferenceConfiguration } from '@scalar/api-reference'
|
||||
import type { ReferenceConfiguration } from '@scalar/types'
|
||||
import type { ElysiaSwaggerConfig } from './types'
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import scalarElysiaTheme from './theme'
|
||||
import type { OpenAPIV3 } from 'openapi-types'
|
||||
import type { ReferenceConfiguration } from '@scalar/api-reference'
|
||||
import type { ReferenceConfiguration } from '@scalar/types'
|
||||
|
||||
export const ScalarRender = (
|
||||
info: OpenAPIV3.InfoObject,
|
||||
|
||||
@@ -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
@@ -1,5 +1,5 @@
|
||||
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'
|
||||
|
||||
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
|
||||
@@ -44,7 +44,7 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
|
||||
/**
|
||||
* Scalar configuration to customize scalar
|
||||
*'
|
||||
* @see https://github.com/scalar/scalar
|
||||
* @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md
|
||||
*/
|
||||
scalarConfig?: ReferenceConfiguration
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ describe('Swagger', () => {
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('follow title and description', async () => {
|
||||
it('follow title and description with Swagger-UI provider', async () => {
|
||||
const app = new Elysia().use(
|
||||
swagger({
|
||||
version: '4.5.0',
|
||||
@@ -75,6 +75,36 @@ describe('Swagger', () => {
|
||||
).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 () => {
|
||||
const app = new Elysia().use(
|
||||
swagger({
|
||||
|
||||
Reference in New Issue
Block a user