Skip to content

Commit

Permalink
remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredCE committed May 21, 2023
1 parent ee72d4f commit 219d335
Showing 1 changed file with 0 additions and 75 deletions.
75 changes: 0 additions & 75 deletions src/definitionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ const path = require('path')

const { v4: uuid } = require('uuid')
const validator = require('oas-validator');
const SchemaConvertor = require('json-schema-for-openapi')
const $RefParser = require("@apidevtools/json-schema-ref-parser")
const isEqual = require('lodash.isequal')

const SchemaHandler = require('./schemaHandler')

Expand Down Expand Up @@ -73,8 +70,6 @@ class DefinitionGenerator {

await this.schemaHandler.addModelsToOpenAPI()
.catch(err => {
console.log('got here')
console.log(this.openAPI)
throw err
})

Expand Down Expand Up @@ -555,76 +550,6 @@ class DefinitionGenerator {
return params;
}

async dereferenceSchema(schema) {
let originalSchema = await $RefParser.bundle(schema, this.refParserOptions)
.catch(err => {
console.error(err)
throw err
})

let deReferencedSchema = await $RefParser.dereference(originalSchema, this.refParserOptions)
.catch(err => {
console.error(err)
throw err
})

// deal with schemas that have been de-referenced poorly: naive
if (deReferencedSchema?.$ref === '#') {
const oldRef = originalSchema.$ref
const path = oldRef.split('/')

const pathTitle = path[path.length - 1]
const referencedProperties = deReferencedSchema.definitions[pathTitle]

Object.assign(deReferencedSchema, { ...referencedProperties })

delete deReferencedSchema.$ref
deReferencedSchema = await this.dereferenceSchema(deReferencedSchema)
.catch((err) => {
throw err
})
}

return deReferencedSchema
}

async schemaCreator(schema, name) {
let schemaName = name
let finalName = schemaName
const dereferencedSchema = await this.dereferenceSchema(schema)
.catch(err => {
console.error(err)
throw err
})

const convertedSchemas = SchemaConvertor.convert(dereferencedSchema, schemaName)

for (const convertedSchemaName of Object.keys(convertedSchemas.schemas)) {
const convertedSchema = convertedSchemas.schemas[convertedSchemaName]
if (this.existsInComponents(convertedSchemaName)) {
if (this.isTheSameSchema(convertedSchema, convertedSchemaName) === false) {
if (convertedSchemaName === schemaName) {
finalName = `${schemaName}-${uuid()}`
this.addToComponents(this.componentTypes.schemas, convertedSchema, finalName)
} else
this.addToComponents(this.componentTypes.schemas, convertedSchema, convertedSchemaName)
}
} else {
this.addToComponents(this.componentTypes.schemas, convertedSchema, convertedSchemaName)
}
}

return `#/components/schemas/${finalName}`
}

existsInComponents(name) {
return Boolean(this.openAPI?.components?.schemas?.[name])
}

isTheSameSchema(schema, otherSchemaName) {
return isEqual(schema, this.openAPI.components.schemas[otherSchemaName])
}

addToComponents(type, schema, name) {
const schemaObj = {
[name]: schema
Expand Down

0 comments on commit 219d335

Please sign in to comment.