🎉 feat: merge pr

This commit is contained in:
saltyaom
2023-09-26 18:02:38 +07:00
parent 37e0697c51
commit 37b9ddf6d1
7 changed files with 78 additions and 50 deletions
+13
View File
@@ -1,3 +1,16 @@
# 0.7.3 - 26 Sep 2023
Feature:
- [#19](https://github.com/elysiajs/elysia-swagger/pull/19) feat: handle nullish response types
- [#18](https://github.com/elysiajs/elysia-swagger/pull/18) swagger ui options
Improvement:
- [#23](https://github.com/elysiajs/elysia-swagger/pull/23) Add github action to run bun test
- remove `removeComment` from tsconfig to show JSDoc
Bug fix:
- [#16](https://github.com/elysiajs/elysia-swagger/pull/16) fix: use global prefix
# 0.7.2 - 21 Sep 2023
Bug fix:
- Paths is undefined
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@elysiajs/swagger",
"version": "0.7.2",
"version": "0.7.3",
"description": "Plugin for Elysia to auto-generate Swagger page",
"author": {
"name": "saltyAom",
@@ -40,7 +40,7 @@
"devDependencies": {
"@types/node": "^20.1.4",
"bun-types": "^0.7.0",
"elysia": "0.7.5",
"elysia": "0.7.10",
"eslint": "^8.40.0",
"rimraf": "4.3",
"typescript": "^5.0.4"
+15 -17
View File
@@ -18,14 +18,14 @@ export const swagger =
excludeStaticFile = true,
path = '/swagger' as Path,
exclude = [],
swaggerOptions = {},
swaggerOptions = {}
}: ElysiaSwaggerConfig<Path> = {
documentation: {},
version: '4.18.2',
excludeStaticFile: true,
path: '/swagger' as Path,
exclude: [],
swaggerOptions: {},
swaggerOptions: {}
}
) =>
(app: Elysia) => {
@@ -34,26 +34,26 @@ export const swagger =
const info = {
title: 'Elysia Documentation',
description: 'Developement documentation',
description: 'Development documentation',
version: '0.0.0',
...documentation.info
}
const pathWithPrefix = `${app.config.prefix}${path}`;
const pathWithPrefix = `${app.config.prefix}${path}`
app.get(path, () => {
const combinedSwaggerOptions = {
url: '${pathWithPrefix}/json',
dom_id: '#swagger-ui',
...swaggerOptions
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;
const stringifiedSwaggerOptions = JSON.stringify(
combinedSwaggerOptions,
(key, value) => {
if (typeof value == 'function') {
return undefined
} else {
return value
}
}
)
@@ -92,8 +92,6 @@ export const swagger =
}
)
}).get(`${path}/json`, () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const routes = app.routes as InternalRoute[]
if (routes.length !== totalRoutes) {
+46 -29
View File
@@ -64,6 +64,9 @@ describe('Swagger', () => {
const res = await app.handle(req('/v2/swagger'))
expect(res.status).toBe(200)
const resJson = await app.handle(req('/v2/swagger/json'))
expect(resJson.status).toBe(200)
})
it('Swagger UI options', async () => {
@@ -75,56 +78,70 @@ describe('Swagger', () => {
})
)
const res = await app.handle(req('/swagger')).then((x) => x.text())
const expected = `
window.onload = () => {
window.ui = SwaggerUIBundle({"url":"/swagger/json","dom_id":"#swagger-ui","persistAuthorization":true});
};
`
const expected = `"persistAuthorization":true`
expect(res.trim().includes(expected.trim())).toBe(true)
})
it('should not return content response when using Void type', async () => {
const app = new Elysia().use(
swagger())
.get('/void', () => {}, {
response: { 204: t.Void({
const app = new Elysia().use(swagger()).get('/void', () => {}, {
response: {
204: t.Void({
description: 'Void response'
})}});
})
}
})
const res = await app.handle(req('/swagger/json'))
expect(res.status).toBe(200)
const response = await res.json();
expect(response.paths['/void'].get.responses['204'].description).toBe('Void response');
expect(response.paths['/void'].get.responses['204'].content).toBeUndefined();
const response = await res.json()
expect(response.paths['/void'].get.responses['204'].description).toBe(
'Void response'
)
expect(
response.paths['/void'].get.responses['204'].content
).toBeUndefined()
})
it('should not return content response when using Undefined type', async () => {
const app = new Elysia().use(
swagger())
const app = new Elysia()
.use(swagger())
.get('/undefined', () => undefined, {
response: { 204: t.Undefined({
description: 'Undefined response'
})}});
response: {
204: t.Undefined({
description: 'Undefined response'
})
}
})
const res = await app.handle(req('/swagger/json'))
expect(res.status).toBe(200)
const response = await res.json();
expect(response.paths['/undefined'].get.responses['204'].description).toBe('Undefined response');
expect(response.paths['/undefined'].get.responses['204'].content).toBeUndefined();
const response = await res.json()
expect(
response.paths['/undefined'].get.responses['204'].description
).toBe('Undefined response')
expect(
response.paths['/undefined'].get.responses['204'].content
).toBeUndefined()
})
it('should not return content response when using Null type', async () => {
const app = new Elysia().use(
swagger())
.get('/null', () => null, {
response: { 204: t.Null({
const app = new Elysia().use(swagger()).get('/null', () => null, {
response: {
204: t.Null({
description: 'Null response'
})}});
})
}
})
const res = await app.handle(req('/swagger/json'))
expect(res.status).toBe(200)
const response = await res.json();
expect(response.paths['/null'].get.responses['204'].description).toBe('Null response');
expect(response.paths['/null'].get.responses['204'].content).toBeUndefined();
const response = await res.json()
expect(response.paths['/null'].get.responses['204'].description).toBe(
'Null response'
)
expect(
response.paths['/null'].get.responses['204'].content
).toBeUndefined()
})
})
+1 -1
View File
@@ -50,7 +50,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist/cjs", /* Specify an output folder for all emitted files. */
"removeComments": true, /* Disable emitting comments. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
+1 -1
View File
@@ -50,7 +50,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"removeComments": true, /* Disable emitting comments. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */