From 13f0f2ad8c5710f00fe02071c12d0b0af3946a48 Mon Sep 17 00:00:00 2001 From: ViniciusCestarii Date: Tue, 11 Mar 2025 13:36:01 -0300 Subject: [PATCH 1/2] feat: add property to change openapi version --- src/index.ts | 4 +++- src/types.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 562bea2..fa8c001 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ export const swagger = async ( scalarCDN = '', scalarConfig = {}, documentation = {}, + openapi = '3.0.3', version = '5.9.0', excludeStaticFile = true, path = '/swagger' as Path, @@ -37,6 +38,7 @@ export const swagger = async ( scalarCDN: '', scalarConfig: {}, documentation: {}, + openapi: '3.0.3', version: '5.9.0', excludeStaticFile: true, path: '/swagger' as Path, @@ -152,7 +154,7 @@ export const swagger = async ( } return { - openapi: '3.0.3', + openapi: openapi, ...{ ...documentation, tags: documentation.tags?.filter( diff --git a/src/types.ts b/src/types.ts index 5370e38..52ed303 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,6 +47,12 @@ export interface ElysiaSwaggerConfig { * @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md */ scalarConfig?: ReferenceConfiguration + /** + * OpenAPI version to be used + * + * @default 3.0.3 + */ + openapi?: string; /** * Version to use for swagger cdn bundle * From 46f7f417c7dd0748ab314e3dcf7d1f27076adcb4 Mon Sep 17 00:00:00 2001 From: ViniciusCestarii Date: Tue, 11 Mar 2025 13:36:19 -0300 Subject: [PATCH 2/2] feat: add test for openapi version --- test/index.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 868be79..dd0c991 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -139,6 +139,19 @@ describe('Swagger', () => { expect(res.trim().includes(expected.trim())).toBe(true) }) + it('OpenAPI version', async () => { + const app = new Elysia().use( + swagger({ + openapi: '3.1.0' + }) + ) + + await app.modules + + const res = await app.handle(req('/swagger/json')).then((x) => x.json()) + expect(res.openapi).toBe('3.1.0') + }) + it('should not return content response when using Void type', async () => { const app = new Elysia().use(swagger()).get('/void', () => {}, { response: {