Skip to content

Commit

Permalink
review update
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Jul 12, 2023
1 parent b7e8758 commit c24ee67
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const getComponentExternalSchema = (json) => {
let title = ''
if (ref.includes('x-schemas')) {
if (ref.split('/')[2] !== json.info.title) {
title = ref.split('/')[2].toLowerCase()
title = ref.split('/')[2]
}
}
title && !refSchemas.includes(title) ? refSchemas.push(title) : null
Expand Down Expand Up @@ -361,7 +361,7 @@ const addContentDescriptorSubSchema = (descriptor, prefix, obj) => {
}

// only consider sub-objects and sub enums to be sub-schemas
const isSubSchema = (schema) => schema.type === 'object' || (schema.type === 'string' && schema.enum)
const isSubSchema = (schema) => schema.type === 'object' || (schema.type === 'string' && schema.enum) || (schema.type === 'array' && schema.items)

const promoteAndNameSubSchemas = (obj) => {
// make a copy so we don't polute our inputs
Expand Down Expand Up @@ -584,11 +584,11 @@ function insertTableofContents(content) {
}

const convertEnumTemplate = (schema, templateName, templates) => {
let enm = getEnum(schema)
let sch = getSchema(schema)
const template = getTemplate(templateName, templates).split('\n')
for (var i = 0; i < template.length; i++) {
if (template[i].indexOf('${key}') >= 0) {
template[i] = enm.enum.map(value => {
template[i] = sch.enum && sch.enum.map(value => {
const safeName = value.split(':').pop().replace(/[\.\-]/g, '_').replace(/\+/g, '_plus').replace(/([a-z])([A-Z0-9])/g, '$1_$2').toUpperCase()
return template[i].replace(/\$\{key\}/g, safeName)
.replace(/\$\{value\}/g, value)
Expand Down Expand Up @@ -694,11 +694,11 @@ function sortSchemasByReference(schemas = []) {
return schemas
}

const getEnum = x => x.type && x.type === 'array' ? x.items : x
const getSchema = x => x.type && x.type === 'array' && x.items ? x.items : x

const isEnum = x => {
let enm = getEnum(x)
return enm.type && enm.type === 'string' && Array.isArray(enm.enum) && x.title
let schema = getSchema(x)
return schema.type && schema.type === 'string' && Array.isArray(schema.enum) && x.title
}

function generateSchemas(json, templates, options) {
Expand Down

0 comments on commit c24ee67

Please sign in to comment.