@@ -410,6 +410,14 @@ class DefinitionGenerator {
410410 return params ;
411411 }
412412
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+
413421 async schemaCreator ( schema , name ) {
414422 const addToComponents = ( schema , name ) => {
415423 const schemaObj = {
@@ -433,22 +441,35 @@ class DefinitionGenerator {
433441 }
434442 }
435443
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 ) => {
439446 throw err
440447 } )
441448
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+ }
442463
443- const convertedSchema = SchemaConvertor . convert ( deReferencedSchema )
464+ const convertedSchema = SchemaConvertor . convert ( deReferencedSchema , name )
444465 let schemaName = name
445466 if ( this . schemaIDs . includes ( schemaName ) )
446467 schemaName = `${ name } -${ uuid ( ) } `
447468
448469 this . schemaIDs . push ( schemaName )
449470
450471 for ( const key of Object . keys ( convertedSchema . schemas ) ) {
451- if ( key === 'main' || key . split ( '-' ) [ 0 ] === 'main' ) {
472+ if ( key === name || key . split ( '-' ) [ 0 ] === name ) {
452473 let ref = `#/components/schemas/`
453474
454475 if ( this . openAPI ?. components ?. schemas ?. [ name ] ) {
0 commit comments