@@ -4,9 +4,6 @@ const path = require('path')
44
55const { v4 : uuid } = require ( 'uuid' )
66const validator = require ( 'oas-validator' ) ;
7- const SchemaConvertor = require ( 'json-schema-for-openapi' )
8- const $RefParser = require ( "@apidevtools/json-schema-ref-parser" )
9- const isEqual = require ( 'lodash.isequal' )
107
118const SchemaHandler = require ( './schemaHandler' )
129
@@ -73,8 +70,6 @@ class DefinitionGenerator {
7370
7471 await this . schemaHandler . addModelsToOpenAPI ( )
7572 . catch ( err => {
76- console . log ( 'got here' )
77- console . log ( this . openAPI )
7873 throw err
7974 } )
8075
@@ -555,76 +550,6 @@ class DefinitionGenerator {
555550 return params ;
556551 }
557552
558- async dereferenceSchema ( schema ) {
559- let originalSchema = await $RefParser . bundle ( schema , this . refParserOptions )
560- . catch ( err => {
561- console . error ( err )
562- throw err
563- } )
564-
565- let deReferencedSchema = await $RefParser . dereference ( originalSchema , this . refParserOptions )
566- . catch ( err => {
567- console . error ( err )
568- throw err
569- } )
570-
571- // deal with schemas that have been de-referenced poorly: naive
572- if ( deReferencedSchema ?. $ref === '#' ) {
573- const oldRef = originalSchema . $ref
574- const path = oldRef . split ( '/' )
575-
576- const pathTitle = path [ path . length - 1 ]
577- const referencedProperties = deReferencedSchema . definitions [ pathTitle ]
578-
579- Object . assign ( deReferencedSchema , { ...referencedProperties } )
580-
581- delete deReferencedSchema . $ref
582- deReferencedSchema = await this . dereferenceSchema ( deReferencedSchema )
583- . catch ( ( err ) => {
584- throw err
585- } )
586- }
587-
588- return deReferencedSchema
589- }
590-
591- async schemaCreator ( schema , name ) {
592- let schemaName = name
593- let finalName = schemaName
594- const dereferencedSchema = await this . dereferenceSchema ( schema )
595- . catch ( err => {
596- console . error ( err )
597- throw err
598- } )
599-
600- const convertedSchemas = SchemaConvertor . convert ( dereferencedSchema , schemaName )
601-
602- for ( const convertedSchemaName of Object . keys ( convertedSchemas . schemas ) ) {
603- const convertedSchema = convertedSchemas . schemas [ convertedSchemaName ]
604- if ( this . existsInComponents ( convertedSchemaName ) ) {
605- if ( this . isTheSameSchema ( convertedSchema , convertedSchemaName ) === false ) {
606- if ( convertedSchemaName === schemaName ) {
607- finalName = `${ schemaName } -${ uuid ( ) } `
608- this . addToComponents ( this . componentTypes . schemas , convertedSchema , finalName )
609- } else
610- this . addToComponents ( this . componentTypes . schemas , convertedSchema , convertedSchemaName )
611- }
612- } else {
613- this . addToComponents ( this . componentTypes . schemas , convertedSchema , convertedSchemaName )
614- }
615- }
616-
617- return `#/components/schemas/${ finalName } `
618- }
619-
620- existsInComponents ( name ) {
621- return Boolean ( this . openAPI ?. components ?. schemas ?. [ name ] )
622- }
623-
624- isTheSameSchema ( schema , otherSchemaName ) {
625- return isEqual ( schema , this . openAPI . components . schemas [ otherSchemaName ] )
626- }
627-
628553 addToComponents ( type , schema , name ) {
629554 const schemaObj = {
630555 [ name ] : schema
0 commit comments