@@ -410,6 +410,14 @@ class DefinitionGenerator {
410
410
return params ;
411
411
}
412
412
413
+ async dereferenceSchema ( schema ) {
414
+ return await $RefParser . dereference ( schema , this . refParserOptions )
415
+ . catch ( err => {
416
+ console . error ( err )
417
+ throw err
418
+ } )
419
+ }
420
+
413
421
async schemaCreator ( schema , name ) {
414
422
const addToComponents = ( schema , name ) => {
415
423
const schemaObj = {
@@ -433,22 +441,35 @@ class DefinitionGenerator {
433
441
}
434
442
}
435
443
436
- const deReferencedSchema = await $RefParser . dereference ( schema , this . refParserOptions )
437
- . catch ( err => {
438
- console . error ( err )
444
+ let deReferencedSchema = await this . dereferenceSchema ( schema )
445
+ . catch ( ( err ) => {
439
446
throw err
440
447
} )
441
448
449
+ // deal with schemas that have been de-referenced poorly
450
+ if ( deReferencedSchema . $ref === '#' ) {
451
+ const oldRef = schema . $ref
452
+ const path = oldRef . split ( '/' )
453
+
454
+ const pathTitle = path [ path . length - 1 ]
455
+ const property = deReferencedSchema . definitions [ path [ path . length - 1 ] ]
456
+ Object . assign ( deReferencedSchema , { properties : { [ pathTitle ] : property } } )
457
+ delete deReferencedSchema . $ref
458
+ deReferencedSchema = await this . dereferenceSchema ( deReferencedSchema )
459
+ . catch ( ( err ) => {
460
+ throw err
461
+ } )
462
+ }
442
463
443
- const convertedSchema = SchemaConvertor . convert ( deReferencedSchema )
464
+ const convertedSchema = SchemaConvertor . convert ( deReferencedSchema , name )
444
465
let schemaName = name
445
466
if ( this . schemaIDs . includes ( schemaName ) )
446
467
schemaName = `${ name } -${ uuid ( ) } `
447
468
448
469
this . schemaIDs . push ( schemaName )
449
470
450
471
for ( const key of Object . keys ( convertedSchema . schemas ) ) {
451
- if ( key === 'main' || key . split ( '-' ) [ 0 ] === 'main' ) {
472
+ if ( key === name || key . split ( '-' ) [ 0 ] === name ) {
452
473
let ref = `#/components/schemas/`
453
474
454
475
if ( this . openAPI ?. components ?. schemas ?. [ name ] ) {
0 commit comments