Skip to content

Commit

Permalink
feat: update scalar configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Aug 4, 2024
1 parent bf58e93 commit cd60bd9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 104 deletions.
Binary file modified bun.lockb
Binary file not shown.
146 changes: 73 additions & 73 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
{
"name": "@elysiajs/swagger",
"version": "1.1.0",
"description": "Plugin for Elysia to auto-generate Swagger page",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
"name": "@elysiajs/swagger",
"version": "1.1.0",
"description": "Plugin for Elysia to auto-generate Swagger page",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
},
"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"
},
"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"
},
"./scalar/types": {
"types": "./dist/scalar/types/index.d.ts",
"import": "./dist/scalar/types/index.mjs",
"require": "./dist/cjs/scalar/types/index.js"
}
"./types": {
"types": "./dist/types.d.ts",
"import": "./dist/types.mjs",
"require": "./dist/cjs/types.js"
},
"keywords": [
"elysia",
"swagger"
],
"homepage": "https://github.com/elysiajs/elysia-swagger",
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-swagger"
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.mjs",
"require": "./dist/cjs/utils.js"
},
"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"
"./scalar": {
"types": "./dist/scalar/index.d.ts",
"import": "./dist/scalar/index.mjs",
"require": "./dist/cjs/scalar/index.js"
},
"peerDependencies": {
"elysia": ">= 1.1.0"
"./scalar/theme": {
"types": "./dist/scalar/theme.d.ts",
"import": "./dist/scalar/theme.mjs",
"require": "./dist/cjs/scalar/theme.js"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@scalar/api-reference": "^1.12.5",
"@types/bun": "1.1.6",
"@types/lodash.clonedeep": "^4.5.9",
"elysia": ">= 1.1.0-rc.2",
"eslint": "9.6.0",
"tsup": "^8.1.0",
"typescript": "^5.5.3"
},
"dependencies": {
"lodash.clonedeep": "^4.5.0",
"openapi-types": "^12.1.3"
"./scalar/types": {
"types": "./dist/scalar/types/index.d.ts",
"import": "./dist/scalar/types/index.mjs",
"require": "./dist/cjs/scalar/types/index.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.1.0"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@scalar/api-reference": "^1.24.68",
"@types/bun": "1.1.6",
"@types/lodash.clonedeep": "^4.5.9",
"elysia": ">= 1.1.0-rc.2",
"eslint": "9.6.0",
"tsup": "^8.1.0",
"typescript": "^5.5.3"
},
"dependencies": {
"lodash.clonedeep": "^4.5.0",
"openapi-types": "^12.1.3"
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ReferenceConfiguration } from '@scalar/api-reference'
import type { ElysiaSwaggerConfig } from './types'

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ export const swagger = async <Path extends string = '/swagger'>(
stringifiedSwaggerOptions,
autoDarkMode
)
: ScalarRender(scalarVersion, scalarConfiguration, scalarCDN),
: ScalarRender(info, scalarVersion, scalarConfiguration, scalarCDN),
{
headers: {
'content-type': 'text/html; charset=utf8'
Expand Down
14 changes: 12 additions & 2 deletions src/scalar/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import scalarElysiaTheme from './theme'
import type { ReferenceConfiguration } from './types'
import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from '@scalar/api-reference'

export const ScalarRender = (
info: OpenAPIV3.InfoObject,
version: string,
config: ReferenceConfiguration,
cdn: string
) => `<!doctype html>
<html>
<head>
<title>API Reference</title>
<title>${info.title}</title>
<meta
name="description"
content="${info.description}"
/>
<meta
name="og:description"
content="${info.description}"
/>
<meta charset="utf-8" />
<meta
name="viewport"
Expand Down
26 changes: 0 additions & 26 deletions src/scalar/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
import type { MetaFlatInput } from "./unjead";

export type ReferenceConfiguration = {
/** A string to use one of the color presets */
theme?: ThemeId;
/** The layout to use for the references */
layout?: ReferenceLayoutType;
/** The Swagger/OpenAPI spec to render */
spec?: SpecConfiguration;
/** URL to a request proxy for the API client */
proxy?: string;
/** Whether the spec input should show */
isEditable?: boolean;
/** Whether to show the sidebar */
showSidebar?: boolean;
/** Remove the Scalar branding :( */
/** Key used with CNTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k) */
searchHotKey?: string;
/** If used, passed data will be added to the HTML header. Read more: https://unhead.unjs.io/usage/composables/use-seo-meta */
metaData?: MetaFlatInput;
/** Custom CSS to be added to the page */
customCss?: string;
/** onSpecUpdate is fired on spec/swagger content change */
onSpecUpdate?: (spec: string) => void;
};

export type SpecConfiguration = {
/** URL to a Swagger/OpenAPI file */
url?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from './scalar/types'
import type { ReferenceConfiguration } from '@scalar/api-reference'
import type { SwaggerUIOptions } from './swagger/types'

export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
Expand Down

0 comments on commit cd60bd9

Please sign in to comment.