Skip to content

Commit 37b9ddf

Browse files
committed
🎉 feat: merge pr
1 parent 37e0697 commit 37b9ddf

File tree

7 files changed

+78
-50
lines changed

7 files changed

+78
-50
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# 0.7.3 - 26 Sep 2023
2+
Feature:
3+
- [#19](https://github.com/elysiajs/elysia-swagger/pull/19) feat: handle nullish response types
4+
- [#18](https://github.com/elysiajs/elysia-swagger/pull/18) swagger ui options
5+
6+
7+
Improvement:
8+
- [#23](https://github.com/elysiajs/elysia-swagger/pull/23) Add github action to run bun test
9+
- remove `removeComment` from tsconfig to show JSDoc
10+
11+
Bug fix:
12+
- [#16](https://github.com/elysiajs/elysia-swagger/pull/16) fix: use global prefix
13+
114
# 0.7.2 - 21 Sep 2023
215
Bug fix:
316
- Paths is undefined

bun.lockb

1 Byte
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/swagger",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"description": "Plugin for Elysia to auto-generate Swagger page",
55
"author": {
66
"name": "saltyAom",
@@ -40,7 +40,7 @@
4040
"devDependencies": {
4141
"@types/node": "^20.1.4",
4242
"bun-types": "^0.7.0",
43-
"elysia": "0.7.5",
43+
"elysia": "0.7.10",
4444
"eslint": "^8.40.0",
4545
"rimraf": "4.3",
4646
"typescript": "^5.0.4"

src/index.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ export const swagger =
1818
excludeStaticFile = true,
1919
path = '/swagger' as Path,
2020
exclude = [],
21-
swaggerOptions = {},
21+
swaggerOptions = {}
2222
}: ElysiaSwaggerConfig<Path> = {
2323
documentation: {},
2424
version: '4.18.2',
2525
excludeStaticFile: true,
2626
path: '/swagger' as Path,
2727
exclude: [],
28-
swaggerOptions: {},
28+
swaggerOptions: {}
2929
}
3030
) =>
3131
(app: Elysia) => {
@@ -34,26 +34,26 @@ export const swagger =
3434

3535
const info = {
3636
title: 'Elysia Documentation',
37-
description: 'Developement documentation',
37+
description: 'Development documentation',
3838
version: '0.0.0',
3939
...documentation.info
4040
}
4141

42-
const pathWithPrefix = `${app.config.prefix}${path}`;
42+
const pathWithPrefix = `${app.config.prefix}${path}`
4343

4444
app.get(path, () => {
45-
const combinedSwaggerOptions = {
46-
url: '${pathWithPrefix}/json',
47-
dom_id: '#swagger-ui',
48-
...swaggerOptions
45+
const combinedSwaggerOptions = {
46+
url: `${pathWithPrefix}/json`,
47+
dom_id: '#swagger-ui',
48+
...swaggerOptions
4949
}
50-
const stringifiedSwaggerOptions = JSON.stringify(combinedSwaggerOptions,
51-
(key,value) => {
52-
if (typeof value == "function") {
53-
return undefined;
54-
}
55-
else {
56-
return value;
50+
const stringifiedSwaggerOptions = JSON.stringify(
51+
combinedSwaggerOptions,
52+
(key, value) => {
53+
if (typeof value == 'function') {
54+
return undefined
55+
} else {
56+
return value
5757
}
5858
}
5959
)
@@ -92,8 +92,6 @@ export const swagger =
9292
}
9393
)
9494
}).get(`${path}/json`, () => {
95-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
96-
// @ts-ignore
9795
const routes = app.routes as InternalRoute[]
9896

9997
if (routes.length !== totalRoutes) {

test/index.test.ts

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ describe('Swagger', () => {
6464

6565
const res = await app.handle(req('/v2/swagger'))
6666
expect(res.status).toBe(200)
67+
68+
const resJson = await app.handle(req('/v2/swagger/json'))
69+
expect(resJson.status).toBe(200)
6770
})
6871

6972
it('Swagger UI options', async () => {
@@ -75,56 +78,70 @@ describe('Swagger', () => {
7578
})
7679
)
7780
const res = await app.handle(req('/swagger')).then((x) => x.text())
78-
const expected = `
79-
window.onload = () => {
80-
window.ui = SwaggerUIBundle({"url":"/swagger/json","dom_id":"#swagger-ui","persistAuthorization":true});
81-
};
82-
`
81+
const expected = `"persistAuthorization":true`
82+
8383
expect(res.trim().includes(expected.trim())).toBe(true)
8484
})
8585

8686
it('should not return content response when using Void type', async () => {
87-
const app = new Elysia().use(
88-
swagger())
89-
.get('/void', () => {}, {
90-
response: { 204: t.Void({
87+
const app = new Elysia().use(swagger()).get('/void', () => {}, {
88+
response: {
89+
204: t.Void({
9190
description: 'Void response'
92-
})}});
91+
})
92+
}
93+
})
9394

9495
const res = await app.handle(req('/swagger/json'))
9596
expect(res.status).toBe(200)
96-
const response = await res.json();
97-
expect(response.paths['/void'].get.responses['204'].description).toBe('Void response');
98-
expect(response.paths['/void'].get.responses['204'].content).toBeUndefined();
97+
const response = await res.json()
98+
expect(response.paths['/void'].get.responses['204'].description).toBe(
99+
'Void response'
100+
)
101+
expect(
102+
response.paths['/void'].get.responses['204'].content
103+
).toBeUndefined()
99104
})
100105

101106
it('should not return content response when using Undefined type', async () => {
102-
const app = new Elysia().use(
103-
swagger())
107+
const app = new Elysia()
108+
.use(swagger())
104109
.get('/undefined', () => undefined, {
105-
response: { 204: t.Undefined({
106-
description: 'Undefined response'
107-
})}});
110+
response: {
111+
204: t.Undefined({
112+
description: 'Undefined response'
113+
})
114+
}
115+
})
108116

109117
const res = await app.handle(req('/swagger/json'))
110118
expect(res.status).toBe(200)
111-
const response = await res.json();
112-
expect(response.paths['/undefined'].get.responses['204'].description).toBe('Undefined response');
113-
expect(response.paths['/undefined'].get.responses['204'].content).toBeUndefined();
119+
const response = await res.json()
120+
expect(
121+
response.paths['/undefined'].get.responses['204'].description
122+
).toBe('Undefined response')
123+
expect(
124+
response.paths['/undefined'].get.responses['204'].content
125+
).toBeUndefined()
114126
})
115127

116128
it('should not return content response when using Null type', async () => {
117-
const app = new Elysia().use(
118-
swagger())
119-
.get('/null', () => null, {
120-
response: { 204: t.Null({
129+
const app = new Elysia().use(swagger()).get('/null', () => null, {
130+
response: {
131+
204: t.Null({
121132
description: 'Null response'
122-
})}});
133+
})
134+
}
135+
})
123136

124137
const res = await app.handle(req('/swagger/json'))
125138
expect(res.status).toBe(200)
126-
const response = await res.json();
127-
expect(response.paths['/null'].get.responses['204'].description).toBe('Null response');
128-
expect(response.paths['/null'].get.responses['204'].content).toBeUndefined();
139+
const response = await res.json()
140+
expect(response.paths['/null'].get.responses['204'].description).toBe(
141+
'Null response'
142+
)
143+
expect(
144+
response.paths['/null'].get.responses['204'].content
145+
).toBeUndefined()
129146
})
130147
})

tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5151
// "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. */
5252
"outDir": "./dist/cjs", /* Specify an output folder for all emitted files. */
53-
"removeComments": true, /* Disable emitting comments. */
53+
// "removeComments": true, /* Disable emitting comments. */
5454
// "noEmit": true, /* Disable emitting files from a compilation. */
5555
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5656
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */

tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5151
// "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. */
5252
"outDir": "./dist", /* Specify an output folder for all emitted files. */
53-
"removeComments": true, /* Disable emitting comments. */
53+
// "removeComments": true, /* Disable emitting comments. */
5454
// "noEmit": true, /* Disable emitting files from a compilation. */
5555
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5656
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */

0 commit comments

Comments
 (0)