|
1 |
| -import { Elysia } from 'elysia' |
| 1 | +import { Elysia, t } from 'elysia' |
2 | 2 | import { swagger } from '../src'
|
3 | 3 |
|
4 | 4 | import { describe, expect, it } from 'bun:test'
|
@@ -65,4 +65,49 @@ describe('Swagger', () => {
|
65 | 65 | const res = await app.handle(req('/v2/swagger'))
|
66 | 66 | expect(res.status).toBe(200)
|
67 | 67 | })
|
| 68 | + |
| 69 | + it('should not return content response when using Void type', async () => { |
| 70 | + const app = new Elysia().use( |
| 71 | + swagger()) |
| 72 | + .get('/void', () => {}, { |
| 73 | + response: { 204: t.Void({ |
| 74 | + description: 'Void response' |
| 75 | + })}}); |
| 76 | + |
| 77 | + const res = await app.handle(req('/swagger/json')) |
| 78 | + expect(res.status).toBe(200) |
| 79 | + const response = await res.json(); |
| 80 | + expect(response.paths['/void'].get.responses['204'].description).toBe('Void response'); |
| 81 | + expect(response.paths['/void'].get.responses['204'].content).toBeUndefined(); |
| 82 | + }) |
| 83 | + |
| 84 | + it('should not return content response when using Undefined type', async () => { |
| 85 | + const app = new Elysia().use( |
| 86 | + swagger()) |
| 87 | + .get('/undefined', () => undefined, { |
| 88 | + response: { 204: t.Undefined({ |
| 89 | + description: 'Undefined response' |
| 90 | + })}}); |
| 91 | + |
| 92 | + const res = await app.handle(req('/swagger/json')) |
| 93 | + expect(res.status).toBe(200) |
| 94 | + const response = await res.json(); |
| 95 | + expect(response.paths['/undefined'].get.responses['204'].description).toBe('Undefined response'); |
| 96 | + expect(response.paths['/undefined'].get.responses['204'].content).toBeUndefined(); |
| 97 | + }) |
| 98 | + |
| 99 | + it('should not return content response when using Null type', async () => { |
| 100 | + const app = new Elysia().use( |
| 101 | + swagger()) |
| 102 | + .get('/null', () => null, { |
| 103 | + response: { 204: t.Null({ |
| 104 | + description: 'Null response' |
| 105 | + })}}); |
| 106 | + |
| 107 | + const res = await app.handle(req('/swagger/json')) |
| 108 | + expect(res.status).toBe(200) |
| 109 | + const response = await res.json(); |
| 110 | + expect(response.paths['/null'].get.responses['204'].description).toBe('Null response'); |
| 111 | + expect(response.paths['/null'].get.responses['204'].content).toBeUndefined(); |
| 112 | + }) |
68 | 113 | })
|
0 commit comments