🎉 feat: merge Scalar

This commit is contained in:
saltyaom
2024-01-07 14:14:13 +07:00
parent fe6bfc2a75
commit 1df988377e
4 changed files with 19 additions and 10 deletions

View File

@@ -9,8 +9,8 @@ const app = new Elysia({
swagger({ swagger({
documentation: { documentation: {
info: { info: {
title: 'Elysia', title: 'Elysia Swagger',
version: '0.7.0' version: '0.8.1'
}, },
tags: [ tags: [
{ {
@@ -36,8 +36,8 @@ const app = new Elysia({
}, },
swaggerOptions: { swaggerOptions: {
persistAuthorization: true persistAuthorization: true
}, }
}) })
) )
.use(plugin) .use(plugin)
.listen(8080) .listen(3000)

View File

@@ -43,4 +43,4 @@ const app = new Elysia({
}) })
) )
.use(plugin) .use(plugin)
.listen(8080) .listen(3000)

View File

@@ -1,6 +1,6 @@
{ {
"name": "@elysiajs/swagger", "name": "@elysiajs/swagger",
"version": "0.8.0", "version": "0.8.1",
"description": "Plugin for Elysia to auto-generate Swagger page", "description": "Plugin for Elysia to auto-generate Swagger page",
"author": { "author": {
"name": "saltyAom", "name": "saltyAom",

View File

@@ -1,13 +1,14 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable @typescript-eslint/ban-ts-comment */
import { type Elysia, type InternalRoute } from 'elysia' import { type Elysia, type InternalRoute } from 'elysia'
import { SwaggerUIRender } from './swagger-ui'
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/api-reference'
import type { ElysiaSwaggerConfig } from './types' import type { ElysiaSwaggerConfig } from './types'
import { SwaggerUIRender } from './swagger-ui'
import { ScalarRender } from './scalar'
/** /**
* Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page. * Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page.
@@ -81,8 +82,16 @@ export const swagger =
...scalarConfig ...scalarConfig
} }
return new Response(
return new Response(provider === 'swagger-ui' ? SwaggerUIRender(info, version, theme, stringifiedSwaggerOptions, autoDarkMode) : ScalarRender(scalarVersion, scalarConfiguration), provider === 'swagger-ui'
? SwaggerUIRender(
info,
version,
theme,
stringifiedSwaggerOptions,
autoDarkMode
)
: ScalarRender(scalarVersion, scalarConfiguration),
{ {
headers: { headers: {
'content-type': 'text/html; charset=utf8' 'content-type': 'text/html; charset=utf8'