diff --git a/src/utils.ts b/src/utils.ts index 8707fa3..e341b9c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -44,6 +44,9 @@ const mapTypesResponse = ( required: string[] } ) => { + if (typeof schema === 'object' + && ['void', 'undefined', 'null'].includes(schema.type)) return; + const responses: Record = {} for (const type of types) diff --git a/test/index.test.ts b/test/index.test.ts index e696f48..f100a51 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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(); + }) })