mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2025-12-06 00:36:10 +00:00
feat: handle nullish response types
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Elysia } from 'elysia'
|
||||
import { Elysia, t } from 'elysia'
|
||||
import { swagger } from '../src'
|
||||
|
||||
import { describe, expect, it } from 'bun:test'
|
||||
@@ -65,4 +65,49 @@ describe('Swagger', () => {
|
||||
const res = await app.handle(req('/v2/swagger'))
|
||||
expect(res.status).toBe(200)
|
||||
})
|
||||
|
||||
it('should not return content response when using Void type', async () => {
|
||||
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();
|
||||
})
|
||||
|
||||
it('should not return content response when using Undefined type', async () => {
|
||||
const app = new Elysia().use(
|
||||
swagger())
|
||||
.get('/undefined', () => undefined, {
|
||||
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();
|
||||
})
|
||||
|
||||
it('should not return content response when using Null type', async () => {
|
||||
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();
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user