Skip to content

Commit

Permalink
Merge pull request #1509 from dderevjanik/feat/openid
Browse files Browse the repository at this point in the history
feat: openid
  • Loading branch information
WoH authored Nov 10, 2023
2 parents c94f7e9 + b6dcb41 commit 19f6463
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/runtime/src/swagger/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -396,6 +401,7 @@ export namespace Swagger {
| BasicSecurity
| BasicSecurity3
| BearerSecurity3
| OpenIDSecurity
| OAuth2AccessCodeSecurity
| OAuth2ApplicationSecurity
| OAuth2ImplicitSecurity
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/swagger/schemaDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
});
20 changes: 20 additions & 0 deletions tests/unit/swagger/schemaDetails3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 19f6463

Please sign in to comment.