Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@elysiajs/swagger

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elysiajs/swagger - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

.github/dependabot.yml

7

dist/cjs/index.d.ts
import { type Elysia } from 'elysia';
import type { ElysiaSwaggerConfig } from './types';
export declare const swagger: <Path extends string = "/swagger">({ documentation, version, excludeStaticFile, path, exclude }?: ElysiaSwaggerConfig<Path>) => (app: Elysia) => Elysia<"", {
/**
* Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page.
*
* @see https://github.com/elysiajs/elysia-swagger
*/
export declare const swagger: <Path extends string = "/swagger">({ documentation, version, excludeStaticFile, path, exclude, swaggerOptions, theme, autoDarkMode }?: ElysiaSwaggerConfig<Path>) => (app: Elysia) => Elysia<"", {
request: {};

@@ -5,0 +10,0 @@ store: {};

@@ -5,18 +5,41 @@ "use strict";

const utils_1 = require("./utils");
const swagger = ({ documentation = {}, version = '4.18.2', excludeStaticFile = true, path = '/swagger', exclude = [] } = {
/**
* Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page.
*
* @see https://github.com/elysiajs/elysia-swagger
*/
const swagger = ({ documentation = {}, version = '5.7.2', excludeStaticFile = true, path = '/swagger', exclude = [], swaggerOptions = {}, theme = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`, autoDarkMode = true } = {
documentation: {},
version: '4.18.2',
version: '5.7.2',
excludeStaticFile: true,
path: '/swagger',
exclude: []
exclude: [],
swaggerOptions: {},
autoDarkMode: true
}) => (app) => {
const schema = {};
let totalRoutes = 0;
if (!version)
version = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`;
const info = {
title: 'Elysia Documentation',
description: 'Developement documentation',
description: 'Development documentation',
version: '0.0.0',
...documentation.info
};
const pathWithPrefix = `${app.config.prefix}${path}`;
app.get(path, () => {
const combinedSwaggerOptions = {
url: `${pathWithPrefix}/json`,
dom_id: '#swagger-ui',
...swaggerOptions
};
const stringifiedSwaggerOptions = JSON.stringify(combinedSwaggerOptions, (key, value) => {
if (typeof value == 'function') {
return undefined;
}
else {
return value;
}
});
return new Response(`<!DOCTYPE html>

@@ -36,3 +59,24 @@ <html lang="en">

/>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css" />
${autoDarkMode && typeof theme === 'string'
? `
<style>
@media (prefers-color-scheme: dark) {
body {
background-color: #222;
color: #faf9a;
}
.swagger-ui {
filter: invert(92%) hue-rotate(180deg);
}
.swagger-ui .microlight {
filter: invert(100%) hue-rotate(180deg);
}
}
</style>`
: ''}
${typeof theme === 'string'
? `<link rel="stylesheet" href="${theme}" />`
: `<link rel="stylesheet" media="(prefers-color-scheme: light)" href="${theme.light}" />
<link rel="stylesheet" media="(prefers-color-scheme: dark)" href="${theme.dark}" />`}
</head>

@@ -44,6 +88,3 @@ <body>

window.onload = () => {
window.ui = SwaggerUIBundle({
url: '${path}/json',
dom_id: '#swagger-ui',
});
window.ui = SwaggerUIBundle(${stringifiedSwaggerOptions});
};

@@ -67,2 +108,3 @@ </script>

path: route.path,
// @ts-ignore
models: app.definitions.type,

@@ -91,2 +133,3 @@ contentType: route.hooks.type

schemas: {
// @ts-ignore
...app.definitions.type,

@@ -98,2 +141,3 @@ ...documentation.components?.schemas

});
// This is intentional to prevent deeply nested type
return app;

@@ -100,0 +144,0 @@ };

import type { OpenAPIV3 } from 'openapi-types';
import type { SwaggerUIOptions } from 'swagger-ui';
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
/**
* Customize Swagger config, refers to Swagger 2.0 config
*
* @see https://swagger.io/specification/v2/
*/
documentation?: Omit<Partial<OpenAPIV3.Document>, 'x-express-openapi-additional-middleware' | 'x-express-openapi-validation-strict'>;
/**
* Version to use for swagger cdn bundle
*
* @see unpkg.com/swagger-ui-dist
*
* @default 4.18.2
*/
version?: string;
/**
* Determine if Swagger should exclude static files.
*
* @default true
*/
excludeStaticFile?: boolean;
/**
* The endpoint to expose Swagger
*
* @default '/swagger'
*/
path?: Path;
/**
* Paths to exclude from Swagger endpoint
*
* @default []
*/
exclude?: string | RegExp | (string | RegExp)[];
/**
* Options to send to SwaggerUIBundle
* Currently, options that are defined as functions such as requestInterceptor
* and onComplete are not supported.
*/
swaggerOptions?: Omit<Partial<SwaggerUIOptions>, 'dom_id' | 'dom_node' | 'spec' | 'url' | 'urls' | 'layout' | 'pluginsOptions' | 'plugins' | 'presets' | 'onComplete' | 'requestInterceptor' | 'responseInterceptor' | 'modelPropertyMacro' | 'parameterMacro'>;
/**
* Custom Swagger CSS
*/
theme?: string | {
light: string;
dark: string;
};
/**
* Using poor man dark mode 😭
*/
autoDarkMode?: boolean;
}

@@ -23,6 +23,9 @@ "use strict";

return Object.entries(schema?.properties ?? []).map(([key, value]) => ({
// @ts-ignore
...value,
in: name,
name: key,
// @ts-ignore
type: value?.type,
// @ts-ignore
required: schema.required?.includes(key) ?? false

@@ -33,2 +36,5 @@ }));

const mapTypesResponse = (types, schema) => {
if (typeof schema === 'object'
&& ['void', 'undefined', 'null'].includes(schema.type))
return;
const responses = {};

@@ -101,2 +107,3 @@ for (const type of types)

return;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, properties, required, ...rest } = models[value];

@@ -127,4 +134,6 @@ responseSchema[key] = {

return;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, properties, required, ...rest } = models[responseSchema];
responseSchema = {
// @ts-ignore
'200': {

@@ -131,0 +140,0 @@ ...rest,

import { type Elysia } from 'elysia';
import type { ElysiaSwaggerConfig } from './types';
export declare const swagger: <Path extends string = "/swagger">({ documentation, version, excludeStaticFile, path, exclude }?: ElysiaSwaggerConfig<Path>) => (app: Elysia) => Elysia<"", {
/**
* Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page.
*
* @see https://github.com/elysiajs/elysia-swagger
*/
export declare const swagger: <Path extends string = "/swagger">({ documentation, version, excludeStaticFile, path, exclude, swaggerOptions, theme, autoDarkMode }?: ElysiaSwaggerConfig<Path>) => (app: Elysia) => Elysia<"", {
request: {};

@@ -5,0 +10,0 @@ store: {};

import { filterPaths, registerSchemaPath } from './utils';
export const swagger = ({ documentation = {}, version = '4.18.2', excludeStaticFile = true, path = '/swagger', exclude = [] } = {
/**
* Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page.
*
* @see https://github.com/elysiajs/elysia-swagger
*/
export const swagger = ({ documentation = {}, version = '5.7.2', excludeStaticFile = true, path = '/swagger', exclude = [], swaggerOptions = {}, theme = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`, autoDarkMode = true } = {
documentation: {},
version: '4.18.2',
version: '5.7.2',
excludeStaticFile: true,
path: '/swagger',
exclude: []
exclude: [],
swaggerOptions: {},
autoDarkMode: true
}) => (app) => {
const schema = {};
let totalRoutes = 0;
if (!version)
version = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`;
const info = {
title: 'Elysia Documentation',
description: 'Developement documentation',
description: 'Development documentation',
version: '0.0.0',
...documentation.info
};
const pathWithPrefix = `${app.config.prefix}${path}`;
app.get(path, () => {
const combinedSwaggerOptions = {
url: `${pathWithPrefix}/json`,
dom_id: '#swagger-ui',
...swaggerOptions
};
const stringifiedSwaggerOptions = JSON.stringify(combinedSwaggerOptions, (key, value) => {
if (typeof value == 'function') {
return undefined;
}
else {
return value;
}
});
return new Response(`<!DOCTYPE html>

@@ -32,3 +55,24 @@ <html lang="en">

/>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css" />
${autoDarkMode && typeof theme === 'string'
? `
<style>
@media (prefers-color-scheme: dark) {
body {
background-color: #222;
color: #faf9a;
}
.swagger-ui {
filter: invert(92%) hue-rotate(180deg);
}
.swagger-ui .microlight {
filter: invert(100%) hue-rotate(180deg);
}
}
</style>`
: ''}
${typeof theme === 'string'
? `<link rel="stylesheet" href="${theme}" />`
: `<link rel="stylesheet" media="(prefers-color-scheme: light)" href="${theme.light}" />
<link rel="stylesheet" media="(prefers-color-scheme: dark)" href="${theme.dark}" />`}
</head>

@@ -40,6 +84,3 @@ <body>

window.onload = () => {
window.ui = SwaggerUIBundle({
url: '${path}/json',
dom_id: '#swagger-ui',
});
window.ui = SwaggerUIBundle(${stringifiedSwaggerOptions});
};

@@ -63,2 +104,3 @@ </script>

path: route.path,
// @ts-ignore
models: app.definitions.type,

@@ -87,2 +129,3 @@ contentType: route.hooks.type

schemas: {
// @ts-ignore
...app.definitions.type,

@@ -94,4 +137,5 @@ ...documentation.components?.schemas

});
// This is intentional to prevent deeply nested type
return app;
};
export default swagger;
import type { OpenAPIV3 } from 'openapi-types';
import type { SwaggerUIOptions } from 'swagger-ui';
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
/**
* Customize Swagger config, refers to Swagger 2.0 config
*
* @see https://swagger.io/specification/v2/
*/
documentation?: Omit<Partial<OpenAPIV3.Document>, 'x-express-openapi-additional-middleware' | 'x-express-openapi-validation-strict'>;
/**
* Version to use for swagger cdn bundle
*
* @see unpkg.com/swagger-ui-dist
*
* @default 4.18.2
*/
version?: string;
/**
* Determine if Swagger should exclude static files.
*
* @default true
*/
excludeStaticFile?: boolean;
/**
* The endpoint to expose Swagger
*
* @default '/swagger'
*/
path?: Path;
/**
* Paths to exclude from Swagger endpoint
*
* @default []
*/
exclude?: string | RegExp | (string | RegExp)[];
/**
* Options to send to SwaggerUIBundle
* Currently, options that are defined as functions such as requestInterceptor
* and onComplete are not supported.
*/
swaggerOptions?: Omit<Partial<SwaggerUIOptions>, 'dom_id' | 'dom_node' | 'spec' | 'url' | 'urls' | 'layout' | 'pluginsOptions' | 'plugins' | 'presets' | 'onComplete' | 'requestInterceptor' | 'responseInterceptor' | 'modelPropertyMacro' | 'parameterMacro'>;
/**
* Custom Swagger CSS
*/
theme?: string | {
light: string;
dark: string;
};
/**
* Using poor man dark mode 😭
*/
autoDarkMode?: boolean;
}

@@ -16,6 +16,9 @@ import { Kind } from '@sinclair/typebox';

return Object.entries(schema?.properties ?? []).map(([key, value]) => ({
// @ts-ignore
...value,
in: name,
name: key,
// @ts-ignore
type: value?.type,
// @ts-ignore
required: schema.required?.includes(key) ?? false

@@ -25,2 +28,5 @@ }));

const mapTypesResponse = (types, schema) => {
if (typeof schema === 'object'
&& ['void', 'undefined', 'null'].includes(schema.type))
return;
const responses = {};

@@ -91,2 +97,3 @@ for (const type of types)

return;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, properties, required, ...rest } = models[value];

@@ -117,4 +124,6 @@ responseSchema[key] = {

return;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, properties, required, ...rest } = models[responseSchema];
responseSchema = {
// @ts-ignore
'200': {

@@ -121,0 +130,0 @@ ...rest,

103

package.json
{
"name": "@elysiajs/swagger",
"version": "0.7.2",
"description": "Plugin for Elysia to auto-generate Swagger page",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "saltyaom@gmail.com"
},
"main": "./dist/index.js",
"exports": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"types": "./src/index.ts",
"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": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public"
},
"peerDependencies": {
"elysia": ">= 0.7.0"
},
"devDependencies": {
"@types/node": "^20.1.4",
"bun-types": "^0.7.0",
"elysia": "0.7.5",
"eslint": "^8.40.0",
"rimraf": "4.3",
"typescript": "^5.0.4"
},
"dependencies": {
"@types/lodash.clonedeep": "^4.5.7",
"lodash.clonedeep": "^4.5.0",
"openapi-types": "^12.1.3"
}
"name": "@elysiajs/swagger",
"version": "0.7.3",
"description": "Plugin for Elysia to auto-generate Swagger page",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "saltyaom@gmail.com"
},
"main": "./dist/index.js",
"exports": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"types": "./src/index.ts",
"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": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public"
},
"peerDependencies": {
"elysia": ">= 0.7.0"
},
"devDependencies": {
"@types/node": "^20.1.4",
"bun-types": "^0.7.0",
"elysia": "0.7.10",
"eslint": "^8.40.0",
"rimraf": "4.3",
"typescript": "^5.0.4"
},
"dependencies": {
"@types/lodash.clonedeep": "^4.5.7",
"@types/swagger-ui": "^3.52.2",
"lodash.clonedeep": "^4.5.0",
"openapi-types": "^12.1.3"
}
}

@@ -0,1 +1,2 @@

/* eslint-disable @typescript-eslint/ban-ts-comment */
import { type Elysia, type InternalRoute } from 'elysia'

@@ -17,12 +18,17 @@

documentation = {},
version = '4.18.2',
version = '5.7.2',
excludeStaticFile = true,
path = '/swagger' as Path,
exclude = []
exclude = [],
swaggerOptions = {},
theme = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`,
autoDarkMode = true
}: ElysiaSwaggerConfig<Path> = {
documentation: {},
version: '4.18.2',
version: '5.7.2',
excludeStaticFile: true,
path: '/swagger' as Path,
exclude: []
exclude: [],
swaggerOptions: {},
autoDarkMode: true
}

@@ -34,5 +40,8 @@ ) =>

if (!version)
version = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`
const info = {
title: 'Elysia Documentation',
description: 'Developement documentation',
description: 'Development documentation',
version: '0.0.0',

@@ -42,3 +51,21 @@ ...documentation.info

const pathWithPrefix = `${app.config.prefix}${path}`
app.get(path, () => {
const combinedSwaggerOptions = {
url: `${pathWithPrefix}/json`,
dom_id: '#swagger-ui',
...swaggerOptions
}
const stringifiedSwaggerOptions = JSON.stringify(
combinedSwaggerOptions,
(key, value) => {
if (typeof value == 'function') {
return undefined
} else {
return value
}
}
)
return new Response(

@@ -59,3 +86,28 @@ `<!DOCTYPE html>

/>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css" />
${
autoDarkMode && typeof theme === 'string'
? `
<style>
@media (prefers-color-scheme: dark) {
body {
background-color: #222;
color: #faf9a;
}
.swagger-ui {
filter: invert(92%) hue-rotate(180deg);
}
.swagger-ui .microlight {
filter: invert(100%) hue-rotate(180deg);
}
}
</style>`
: ''
}
${
typeof theme === 'string'
? `<link rel="stylesheet" href="${theme}" />`
: `<link rel="stylesheet" media="(prefers-color-scheme: light)" href="${theme.light}" />
<link rel="stylesheet" media="(prefers-color-scheme: dark)" href="${theme.dark}" />`
}
</head>

@@ -67,6 +119,3 @@ <body>

window.onload = () => {
window.ui = SwaggerUIBundle({
url: '${path}/json',
dom_id: '#swagger-ui',
});
window.ui = SwaggerUIBundle(${stringifiedSwaggerOptions});
};

@@ -83,4 +132,2 @@ </script>

}).get(`${path}/json`, () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const routes = app.routes as InternalRoute[]

@@ -87,0 +134,0 @@

import type { OpenAPIV3 } from 'openapi-types'
import type { SwaggerUIOptions } from 'swagger-ui'

@@ -16,5 +17,5 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {

* Version to use for swagger cdn bundle
*
*
* @see unpkg.com/swagger-ui-dist
*
*
* @default 4.18.2

@@ -41,2 +42,35 @@ */

exclude?: string | RegExp | (string | RegExp)[]
/**
* Options to send to SwaggerUIBundle
* Currently, options that are defined as functions such as requestInterceptor
* and onComplete are not supported.
*/
swaggerOptions?: Omit<
Partial<SwaggerUIOptions>,
| 'dom_id'
| 'dom_node'
| 'spec'
| 'url'
| 'urls'
| 'layout'
| 'pluginsOptions'
| 'plugins'
| 'presets'
| 'onComplete'
| 'requestInterceptor'
| 'responseInterceptor'
| 'modelPropertyMacro'
| 'parameterMacro'
>
/**
* Custom Swagger CSS
*/
theme?: string | {
light: string
dark: string
}
/**
* Using poor man dark mode 😭
*/
autoDarkMode?: boolean
}

@@ -47,2 +47,5 @@ import type { HTTPMethod, LocalHook } from 'elysia'

) => {
if (typeof schema === 'object'
&& ['void', 'undefined', 'null'].includes(schema.type)) return;
const responses: Record<string, OpenAPIV3.MediaTypeObject> = {}

@@ -49,0 +52,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc