@@ -396,48 +396,41 @@ class DefinitionGenerator {
396
396
}
397
397
}
398
398
399
- if ( typeof schema !== 'string' && Object . keys ( schema ) . length > 0 ) {
400
- const convertedSchema = SchemaConvertor . convert ( schema )
399
+ const deReferencedSchema = await $RefParser . dereference ( schema , this . refParserOptions )
400
+ . catch ( err => {
401
+ console . error ( err )
402
+ throw err
403
+ } )
401
404
402
- let schemaName = name
403
- if ( this . schemaIDs . includes ( schemaName ) )
404
- schemaName = `${ name } -${ uuid ( ) } `
405
405
406
- this . schemaIDs . push ( schemaName )
406
+ const convertedSchema = SchemaConvertor . convert ( deReferencedSchema )
407
+ let schemaName = name
408
+ if ( this . schemaIDs . includes ( schemaName ) )
409
+ schemaName = `${ name } -${ uuid ( ) } `
407
410
408
- for ( const key of Object . keys ( convertedSchema . schemas ) ) {
409
- if ( key === 'main' || key . split ( '-' ) [ 0 ] === 'main' ) {
410
- let ref = `#/components/schemas/`
411
+ this . schemaIDs . push ( schemaName )
411
412
412
- if ( this . openAPI ?. components ?. schemas ?. [ name ] ) {
413
- if ( JSON . stringify ( convertedSchema . schemas [ key ] ) === JSON . stringify ( this . openAPI . components . schemas [ name ] ) ) {
414
- return `${ ref } ${ name } `
415
- }
413
+ for ( const key of Object . keys ( convertedSchema . schemas ) ) {
414
+ if ( key === 'main' || key . split ( '-' ) [ 0 ] === 'main' ) {
415
+ let ref = `#/components/schemas/`
416
+
417
+ if ( this . openAPI ?. components ?. schemas ?. [ name ] ) {
418
+ if ( JSON . stringify ( convertedSchema . schemas [ key ] ) === JSON . stringify ( this . openAPI . components . schemas [ name ] ) ) {
419
+ return `${ ref } ${ name } `
416
420
}
421
+ }
417
422
418
- addToComponents ( convertedSchema . schemas [ key ] , schemaName )
419
- return `${ ref } ${ schemaName } `
420
- } else {
421
- if ( this . openAPI ?. components ?. schemas ?. [ key ] ) {
422
- if ( JSON . stringify ( convertedSchema . schemas [ key ] ) !== JSON . stringify ( this . openAPI . components . schemas [ key ] ) ) {
423
- addToComponents ( convertedSchema . schemas [ key ] , key )
424
- }
425
- } else {
423
+ addToComponents ( convertedSchema . schemas [ key ] , schemaName )
424
+ return `${ ref } ${ schemaName } `
425
+ } else {
426
+ if ( this . openAPI ?. components ?. schemas ?. [ key ] ) {
427
+ if ( JSON . stringify ( convertedSchema . schemas [ key ] ) !== JSON . stringify ( this . openAPI . components . schemas [ key ] ) ) {
426
428
addToComponents ( convertedSchema . schemas [ key ] , key )
427
429
}
430
+ } else {
431
+ addToComponents ( convertedSchema . schemas [ key ] , key )
428
432
}
429
433
}
430
- } else {
431
- const combinedSchema = await $RefParser . dereference ( schema , this . refParserOptions )
432
- . catch ( err => {
433
- console . error ( err )
434
- throw err
435
- } )
436
-
437
- return await this . schemaCreator ( combinedSchema , name )
438
- . catch ( err => {
439
- throw err
440
- } )
441
434
}
442
435
}
443
436
0 commit comments