From 954db9b3ea8a4d75c3e2fa1beaa3d26409af34bb Mon Sep 17 00:00:00 2001 From: Mohamed Jabarullah Date: Wed, 28 May 2025 15:22:24 +0530 Subject: [PATCH] :arrow_up: feat: update scalar api reference Update scalar api reference to latest version with new config and elysia deps upgrade --- package.json | 150 ++++++++++++++++++++++---------------------- src/index.ts | 21 ++----- src/scalar/index.ts | 20 +++--- src/types.ts | 4 +- 4 files changed, 93 insertions(+), 102 deletions(-) diff --git a/package.json b/package.json index de1a9ad..6b2deb6 100644 --- a/package.json +++ b/package.json @@ -1,76 +1,76 @@ { - "name": "@elysiajs/swagger", - "version": "1.3.0", - "description": "Plugin for Elysia to auto-generate Swagger page", - "author": { - "name": "saltyAom", - "url": "https://github.com/SaltyAom", - "email": "saltyaom@gmail.com" - }, - "main": "./dist/cjs/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "exports": { - "./package.json": "./package.json", - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/cjs/index.js" - }, - "./types": { - "types": "./dist/types.d.ts", - "import": "./dist/types.mjs", - "require": "./dist/cjs/types.js" - }, - "./utils": { - "types": "./dist/utils.d.ts", - "import": "./dist/utils.mjs", - "require": "./dist/cjs/utils.js" - }, - "./scalar": { - "types": "./dist/scalar/index.d.ts", - "import": "./dist/scalar/index.mjs", - "require": "./dist/cjs/scalar/index.js" - }, - "./scalar/theme": { - "types": "./dist/scalar/theme.d.ts", - "import": "./dist/scalar/theme.mjs", - "require": "./dist/cjs/scalar/theme.js" - } - }, - "keywords": [ - "elysia", - "swagger" - ], - "homepage": "https://github.com/elysiajs/elysia-swagger", - "repository": { - "type": "git", - "url": "https://github.com/elysiajs/elysia-swagger" - }, - "bugs": "https://github.com/elysiajs/elysia-swagger/issues", - "license": "MIT", - "scripts": { - "dev": "bun run --watch example/index.ts", - "test": "bun test && npm run test:node", - "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", - "build": "bun build.ts", - "release": "npm run build && npm run test && npm publish --access public" - }, - "peerDependencies": { - "elysia": ">= 1.3.0" - }, - "devDependencies": { - "@apidevtools/swagger-parser": "^10.1.0", - "@types/bun": "1.1.14", - "elysia": "1.3.0-exp.71", - "eslint": "9.6.0", - "tsup": "^8.1.0", - "typescript": "^5.5.3" - }, - "dependencies": { - "@scalar/themes": "^0.9.52", - "@scalar/types": "^0.0.12", - "openapi-types": "^12.1.3", - "pathe": "^1.1.2" - } -} \ No newline at end of file + "name": "@elysiajs/swagger", + "version": "1.3.0", + "description": "Plugin for Elysia to auto-generate Swagger page", + "author": { + "name": "saltyAom", + "url": "https://github.com/SaltyAom", + "email": "saltyaom@gmail.com" + }, + "main": "./dist/cjs/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/cjs/index.js" + }, + "./types": { + "types": "./dist/types.d.ts", + "import": "./dist/types.mjs", + "require": "./dist/cjs/types.js" + }, + "./utils": { + "types": "./dist/utils.d.ts", + "import": "./dist/utils.mjs", + "require": "./dist/cjs/utils.js" + }, + "./scalar": { + "types": "./dist/scalar/index.d.ts", + "import": "./dist/scalar/index.mjs", + "require": "./dist/cjs/scalar/index.js" + }, + "./scalar/theme": { + "types": "./dist/scalar/theme.d.ts", + "import": "./dist/scalar/theme.mjs", + "require": "./dist/cjs/scalar/theme.js" + } + }, + "keywords": [ + "elysia", + "swagger" + ], + "homepage": "https://github.com/elysiajs/elysia-swagger", + "repository": { + "type": "git", + "url": "https://github.com/elysiajs/elysia-swagger" + }, + "bugs": "https://github.com/elysiajs/elysia-swagger/issues", + "license": "MIT", + "scripts": { + "dev": "bun run --watch example/index.ts", + "test": "bun test && npm run test:node", + "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", + "build": "bun build.ts", + "release": "npm run build && npm run test && npm publish --access public" + }, + "peerDependencies": { + "elysia": ">= 1.3.0" + }, + "devDependencies": { + "@apidevtools/swagger-parser": "^10.1.1", + "@types/bun": "1.2.14", + "elysia": "1.3.3", + "eslint": "9.27.0", + "tsup": "^8.5.0", + "typescript": "^5.8.3" + }, + "dependencies": { + "@scalar/themes": "^0.12.1", + "@scalar/types": "^0.2.1", + "openapi-types": "^12.1.3", + "pathe": "^2.0.2" + } +} diff --git a/src/index.ts b/src/index.ts index 4fc45df..67ca042 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import { ScalarRender } from './scalar' import { filterPaths, registerSchemaPath } from './utils' import type { OpenAPIV3 } from 'openapi-types' -import type { ReferenceConfiguration } from '@scalar/types' +import type { ApiReferenceConfiguration } from '@scalar/types' import type { ElysiaSwaggerConfig } from './types' /** @@ -21,7 +21,7 @@ export const swagger = ({ scalarCDN = '', scalarConfig = {}, documentation = {}, - version = '5.9.0', + version = '5.22.0', excludeStaticFile = true, path = '/swagger' as Path, specPath = `${path}/json`, @@ -35,9 +35,6 @@ export const swagger = ({ const schema = {} let totalRoutes = 0 - if (!version) - version = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css` - const info = { title: 'Elysia Documentation', description: 'Development documentation', @@ -45,8 +42,6 @@ export const swagger = ({ ...documentation.info } - const relativePath = path.startsWith('/') ? path.slice(1) : path - const app = new Elysia({ name: '@elysiajs/swagger' }) const page = new Response( @@ -65,22 +60,18 @@ export const swagger = ({ typeof value === 'function' ? undefined : value ), autoDarkMode - ) + ) : ScalarRender( info, scalarVersion, { - spec: { - ...scalarConfig.spec, - url: specPath - }, ...scalarConfig, + url: specPath, // so we can showcase the elysia theme - // @ts-expect-error _integration: 'elysiajs' - } satisfies ReferenceConfiguration, + } satisfies Partial, scalarCDN - ), + ), { headers: { 'content-type': 'text/html; charset=utf8' diff --git a/src/scalar/index.ts b/src/scalar/index.ts index 883ea66..71db5ec 100644 --- a/src/scalar/index.ts +++ b/src/scalar/index.ts @@ -1,12 +1,12 @@ import { elysiajsTheme } from '@scalar/themes' import type { OpenAPIV3 } from 'openapi-types' -import type { ReferenceConfiguration } from '@scalar/types' +import type { ApiReferenceConfiguration } from '@scalar/types' export const ScalarRender = ( - info: OpenAPIV3.InfoObject, - version: string, - config: ReferenceConfiguration, - cdn: string + info: OpenAPIV3.InfoObject, + version: string, + config: Partial, + cdn: string ) => ` @@ -35,14 +35,14 @@ export const ScalarRender = ( + cdn + ? cdn + : `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js` + }" crossorigin> ` diff --git a/src/types.ts b/src/types.ts index ce16c26..a98f696 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ import type { OpenAPIV3 } from 'openapi-types' -import type { ReferenceConfiguration } from '@scalar/types' +import type { ApiReferenceConfiguration } from '@scalar/types' import type { SwaggerUIOptions } from './swagger/types' export interface ElysiaSwaggerConfig { @@ -46,7 +46,7 @@ export interface ElysiaSwaggerConfig { *' * @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md */ - scalarConfig?: ReferenceConfiguration + scalarConfig?: Partial /** * Version to use for swagger cdn bundle *