@@ -40,6 +40,13 @@ export interface ConverterOptions {
4040 authorizationUrl ?: string ;
4141 /** The tokenUrl for openIdConnect -> oauth2 transformation */
4242 tokenUrl ?: string ;
43+ /**
44+ * If `true`, convert `openIdConnect` security scheme
45+ * to `oauth2`. Some tools (even those which purport to support OAS 3.0)
46+ * do not process the `openIdConnect` security scheme
47+ * (I'm looking at you, openapi-generator)
48+ */
49+ convertOpenIdConnectToOAuth2 ?: boolean ;
4350 /** Name of YAML/JSON file with scope descriptions.
4451 * This is a simple map in the format
4552 * `{ scope1: "description of scope1", ... }`
@@ -64,6 +71,7 @@ export class Converter {
6471 private scopeDescriptions = undefined ;
6572 private convertSchemaComments = false ;
6673 private returnCode = 0 ;
74+ private convertOpenIdConnectToOAuth2 : boolean ;
6775
6876 /**
6977 * Construct a new Converter
@@ -76,17 +84,17 @@ export class Converter {
7684 this . allOfTransform = Boolean ( options ?. allOfTransform ) ;
7785 this . authorizationUrl = options ?. authorizationUrl || 'https://www.example.com/oauth2/authorize' ;
7886 this . tokenUrl = options ?. tokenUrl || 'https://www.example.com/oauth2/token' ;
79- this . loadScopeDescriptions ( options ?. scopeDescriptionFile ) ;
87+ this . convertOpenIdConnectToOAuth2 = options ?. convertOpenIdConnectToOAuth2 || ! ! ( options ?. scopeDescriptionFile ) ;
88+ if ( this . convertOpenIdConnectToOAuth2 ) {
89+ this . loadScopeDescriptions ( options . scopeDescriptionFile ) ;
90+ }
8091 this . convertSchemaComments = options ?. convertSchemaComments ;
8192 }
8293
8394 /** Load the scopes.yaml file and save in this.scopeDescriptions
8495 * @throws Error if the file cannot be read or parsed as YAML/JSON
8596 */
8697 private loadScopeDescriptions ( scopeDescriptionFile ?: string ) {
87- if ( ! scopeDescriptionFile ) {
88- return ;
89- }
9098 this . scopeDescriptions = yaml . load ( fs . readFileSync ( scopeDescriptionFile , 'utf8' ) ) ;
9199 }
92100
@@ -136,8 +144,8 @@ export class Converter {
136144 this . removeLicenseIdentifier ( ) ;
137145 this . convertSchemaRef ( ) ;
138146 this . simplifyNonSchemaRef ( ) ;
139- if ( this . scopeDescriptions ) {
140- this . convertSecuritySchemes ( ) ;
147+ if ( this . convertOpenIdConnectToOAuth2 ) {
148+ this . convertOpenIdConnectSecuritySchemesToOAuth2 ( ) ;
141149 }
142150 this . convertJsonSchemaExamples ( ) ;
143151 this . convertJsonSchemaContentEncoding ( ) ;
@@ -373,13 +381,16 @@ export class Converter {
373381 /** HTTP methods */
374382 static readonly HTTP_METHODS = [ 'delete' , 'get' , 'head' , 'options' , 'patch' , 'post' , 'put' , 'trace' ] ;
375383 /**
376- * OpenAPI 3.1 defines a new `openIdConnect` security scheme.
377- * Down-convert the scheme to `oauth2` / authorization code flow.
384+ * OpenAPI 3.0 defines a new `openIdConnect` security scheme
385+ * but not all tools support `openIdConnect`, even if such tools
386+ * claim support for OAS 3.0
387+ * This converts the `openIdConnect` security scheme
388+ * to the `oauth2` security scheme.
378389 * Collect all the scopes used in any security requirements within
379390 * operations and add them to the scheme. Also define the
380391 * URLs to the `authorizationUrl` and `tokenUrl` of `oauth2`.
381392 */
382- convertSecuritySchemes ( ) {
393+ convertOpenIdConnectSecuritySchemesToOAuth2 ( ) {
383394 const oauth2Scopes = ( schemeName : string ) : object => {
384395 const scopes = { } ;
385396 const paths = this . openapi30 ?. paths ;
@@ -410,8 +421,8 @@ export class Converter {
410421 scheme . type = 'oauth2' ;
411422 const openIdConnectUrl = scheme . openIdConnectUrl ;
412423 scheme . description = `OAuth2 Authorization Code Flow. The client may
413- GET the OpenID Connect configuration JSON from \`${ openIdConnectUrl } \`
414- to get the correct \`authorizationUrl\` and \`tokenUrl\`.`;
424+ GET the OpenID Connect configuration JSON from \`${ openIdConnectUrl } \`
425+ to get the correct \`authorizationUrl\` and \`tokenUrl\`.` ;
415426 delete scheme . openIdConnectUrl ;
416427 const scopes = oauth2Scopes ( schemeName ) ;
417428 scheme . flows = {
0 commit comments