diff --git a/packages/runtime/src/swagger/swagger.ts b/packages/runtime/src/swagger/swagger.ts index 275e9daf8..afa56d093 100644 --- a/packages/runtime/src/swagger/swagger.ts +++ b/packages/runtime/src/swagger/swagger.ts @@ -346,6 +346,11 @@ export namespace Swagger { bearerFormat?: string; } + export interface OpenIDSecurity extends BaseSecurity { + type: 'openIdConnect'; + openIdConnectUrl: string; + } + export interface OAuth2Security3 extends BaseSecurity { type: 'oauth2'; flows: OAuthFlow; @@ -396,6 +401,7 @@ export namespace Swagger { | BasicSecurity | BasicSecurity3 | BearerSecurity3 + | OpenIDSecurity | OAuth2AccessCodeSecurity | OAuth2ApplicationSecurity | OAuth2ImplicitSecurity diff --git a/tests/unit/swagger/schemaDetails.spec.ts b/tests/unit/swagger/schemaDetails.spec.ts index 4a6f0518c..444966e21 100644 --- a/tests/unit/swagger/schemaDetails.spec.ts +++ b/tests/unit/swagger/schemaDetails.spec.ts @@ -770,5 +770,26 @@ describe('Schema details generation', () => { // Assert expect(errToTest!.message).to.match(/Swagger 2.0 does not support "http" security scheme/); }); + + it('should reject openId security scheme for OAS2', () => { + const optionsWithOpenId = Object.assign({}, getDefaultExtendedOptions(), { + securityDefinitions: { + openid_auth: { + type: 'openIdConnect', + url: 'https://example.com/.well-known/openid-configuration', + }, + }, + }); + let errToTest: Error | null = null; + try { + const metadata = new MetadataGenerator('./fixtures/controllers/exampleController.ts').Generate(); + new SpecGenerator2(metadata, optionsWithOpenId).GetSpec(); + } catch (err: any) { + errToTest = err; + } + + // Assert + expect(errToTest!.message).to.match(/Swagger 2.0 does not support "openIdConnect" security scheme/); + }); }); }); diff --git a/tests/unit/swagger/schemaDetails3.spec.ts b/tests/unit/swagger/schemaDetails3.spec.ts index 7bc0358e1..79ae260df 100644 --- a/tests/unit/swagger/schemaDetails3.spec.ts +++ b/tests/unit/swagger/schemaDetails3.spec.ts @@ -263,6 +263,26 @@ describe('Definition generation for OpenAPI 3.0.0', () => { bearer, }); }); + + it('should allow openId scheme', () => { + const openId: Swagger.OpenIDSecurity = { + type: 'openIdConnect', + openIdConnectUrl: 'https://example.com/.well-known/openid-configuration' + }; + const optionsWithOpenId = Object.assign({}, defaultOptions, { + securityDefinitions: { + openId, + }, + }); + + const metadata = new MetadataGenerator('./fixtures/controllers/exampleController.ts').Generate(); + const exampleSpec = new SpecGenerator3(metadata, optionsWithOpenId).GetSpec(); + + expect(exampleSpec.components.securitySchemes).to.eql({ + openId, + }); + }); + }); describe('example comment', () => {