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.3.0 to 0.4.0

9

dist/index.d.ts

@@ -1,9 +0,4 @@

import { type Elysia, SCHEMA, DEFS } from 'elysia';
import { type Elysia } from 'elysia';
import type { ElysiaSwaggerConfig } from './types';
export declare const swagger: <Path extends string = "/swagger">({ documentation, excludeStaticFile, path, exclude }?: ElysiaSwaggerConfig<Path>) => (app: Elysia) => Elysia<import("elysia").ElysiaInstance<{
store: Record<string, unknown>;
request: {};
schema: {};
meta: Record<typeof SCHEMA, {}> & Record<typeof DEFS, {}> & Record<typeof import("elysia").EXPOSED, {}>;
}>>;
export declare const swagger: <Path extends string = "/swagger">({ documentation, version, excludeStaticFile, path, exclude }?: ElysiaSwaggerConfig<Path>) => (app: Elysia) => Elysia<import("elysia").ElysiaInstance>;
export default swagger;
import { SCHEMA, DEFS } from 'elysia';
import { staticPlugin } from '@elysiajs/static';
import { getAbsoluteFSPath } from 'swagger-ui-dist';
import { filterPaths, formatSwagger } from './utils';
export const swagger = ({ documentation = {}, excludeStaticFile = true, path = '/swagger', exclude = [] } = {
import { filterPaths } from './utils';
export const swagger = ({ documentation = {}, version = '4.18.2', excludeStaticFile = true, path = '/swagger', exclude = [] } = {
documentation: {},
version: '4.18.2',
excludeStaticFile: true,

@@ -11,28 +10,43 @@ path: '/swagger',

}) => (app) => {
const info = {
title: 'Elysia Documentation',
description: 'Developement documentation',
version: '0.0.0',
...documentation.info
};
app.get(path, (context) => {
return new Response(`<!DOCTYPE HTML>
<html>
return new Response(`<!DOCTYPE html>
<html lang="en">
<head>
<title>Redirecting...</title>
<meta charset="utf8">
<meta http-equiv="refresh" content="0; url=${path}/static/index.html">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${info.title}</title>
<meta
name="description"
content="${info.description}"
/>
<meta
name="og:description"
content="${info.description}"
/>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui-bundle.js" crossorigin></script>
<script>
window.location = ${path}/static/index.html
window.onload = () => {
window.ui = SwaggerUIBundle({
url: '${path}/json',
dom_id: '#swagger-ui',
});
};
</script>
</head>
<body>
If you're not being redirected, use this
<a href=${path}/static/index.html>
link
</a>
</body>
</html>`, {
status: 302,
headers: {
'content-type': 'text/html; charset=utf8',
Location: `${path}/static/index.html`
'content-type': 'text/html; charset=utf8'
}
});
})
.get(`${path}/json`, (content) => ({
}).get(`${path}/json`, (content) => ({
openapi: '3.0.3',

@@ -50,5 +64,3 @@ ...{

excludeStaticFile,
exclude: Array.isArray(exclude)
? exclude
: [exclude]
exclude: Array.isArray(exclude) ? exclude : [exclude]
}),

@@ -58,11 +70,2 @@ components: {

}
}))
.get(`${path}/static/swagger-initializer.js`, () => new Response(formatSwagger(path), {
headers: {
'content-type': 'text/javascript; charset=utf-8'
}
}))
.use(staticPlugin({
prefix: `${path}/static`,
assets: getAbsoluteFSPath()
}));

@@ -69,0 +72,0 @@ return app;

import type { OpenAPIV3 } from 'openapi-types';
export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
documentation?: Omit<Partial<OpenAPIV3.Document>, 'x-express-openapi-additional-middleware' | 'x-express-openapi-validation-strict'>;
version?: string;
excludeStaticFile?: boolean;

@@ -5,0 +6,0 @@ path?: Path;

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

export declare const formatSwagger: (path: string) => string;
export declare const filterPaths: (paths: Record<string, any>, { excludeStaticFile, exclude }: {

@@ -3,0 +2,0 @@ excludeStaticFile: boolean;

@@ -1,16 +0,1 @@

export const formatSwagger = (path) => `window.onload = function() {
window.ui = SwaggerUIBundle({
url: "${path}/json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
};`;
export const filterPaths = (paths, { excludeStaticFile = true, exclude = [] }) => {

@@ -17,0 +2,0 @@ const newPaths = {};

{
"name": "@elysiajs/swagger",
"version": "0.3.0",
"version": "0.4.0",
"description": "Plugin for Elysia to auto-generate Swagger page",

@@ -40,12 +40,7 @@ "author": {

"@types/node": "^18.11.7",
"@types/swagger-ui-dist": "^3.30.1",
"bun-types": "^0.5.7",
"eslint": "^8.26.0",
"elysia": "^0.3.0",
"typescript": "^4.9.4"
},
"dependencies": {
"@elysiajs/static": "0.2.0",
"swagger-ui-dist": "^4.16.0"
"elysia": "^0.4.9",
"typescript": "^5.0.2"
}
}
import { type Elysia, SCHEMA, DEFS } from 'elysia'
import { staticPlugin } from '@elysiajs/static'
import { getAbsoluteFSPath } from 'swagger-ui-dist'
import { filterPaths } from './utils'
import type { OpenAPIV3 } from 'openapi-types'
import { filterPaths, formatSwagger } from './utils'
import type { ElysiaSwaggerConfig } from './types'

@@ -20,2 +18,3 @@

documentation = {},
version = '4.18.2',
excludeStaticFile = true,

@@ -26,2 +25,3 @@ path = '/swagger' as Path,

documentation: {},
version: '4.18.2',
excludeStaticFile: true,

@@ -33,70 +33,69 @@ path: '/swagger' as Path,

(app: Elysia) => {
const info = {
title: 'Elysia Documentation',
description: 'Developement documentation',
version: '0.0.0',
...documentation.info
}
app.get(path, (context) => {
return new Response(
`<!DOCTYPE HTML>
<html>
`<!DOCTYPE html>
<html lang="en">
<head>
<title>Redirecting...</title>
<meta charset="utf8">
<meta http-equiv="refresh" content="0; url=${path}/static/index.html">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${info.title}</title>
<meta
name="description"
content="${info.description}"
/>
<meta
name="og:description"
content="${info.description}"
/>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@${version}/swagger-ui-bundle.js" crossorigin></script>
<script>
window.location = ${path}/static/index.html
window.onload = () => {
window.ui = SwaggerUIBundle({
url: '${path}/json',
dom_id: '#swagger-ui',
});
};
</script>
</head>
<body>
If you're not being redirected, use this
<a href=${path}/static/index.html>
link
</a>
</body>
</html>`,
{
status: 302,
headers: {
'content-type': 'text/html; charset=utf8',
Location: `${path}/static/index.html`
'content-type': 'text/html; charset=utf8'
}
}
)
})
.get(
`${path}/json`,
(content) =>
({
openapi: '3.0.3',
...{
...documentation,
info: {
title: 'Elysia Documentation',
description: 'Developement documentation',
version: '0.0.0',
...documentation.info
}
},
paths: filterPaths(content[SCHEMA], {
excludeStaticFile,
exclude: Array.isArray(exclude)
? exclude
: [exclude]
}),
components: {
schemas: content[DEFS]
}).get(
`${path}/json`,
(content) =>
({
openapi: '3.0.3',
...{
...documentation,
info: {
title: 'Elysia Documentation',
description: 'Developement documentation',
version: '0.0.0',
...documentation.info
}
} satisfies OpenAPIV3.Document)
)
.get(
`${path}/static/swagger-initializer.js`,
() =>
new Response(formatSwagger(path), {
headers: {
'content-type': 'text/javascript; charset=utf-8'
}
})
)
.use(
staticPlugin({
prefix: `${path}/static`,
assets: getAbsoluteFSPath()
})
)
},
paths: filterPaths(content[SCHEMA], {
excludeStaticFile,
exclude: Array.isArray(exclude) ? exclude : [exclude]
}),
components: {
schemas: content[DEFS]
}
} satisfies OpenAPIV3.Document)
)

@@ -103,0 +102,0 @@ // This is intentional to prevent deeply nested type

@@ -15,2 +15,10 @@ import type { OpenAPIV3 } from 'openapi-types'

/**
* 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.

@@ -17,0 +25,0 @@ *

@@ -1,17 +0,1 @@

export const formatSwagger = (path: string) => `window.onload = function() {
window.ui = SwaggerUIBundle({
url: "${path}/json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
};`
export const filterPaths = (

@@ -18,0 +2,0 @@ paths: Record<string, any>,

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