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 * 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: {