Skip to content

Commit

Permalink
fix(sample-gen): fix lift needs config
Browse files Browse the repository at this point in the history
Signed-off-by: mathis-m <mathis.michel@outlook.de>
  • Loading branch information
mathis-m committed Mar 6, 2021
1 parent 3422b97 commit b3f81ad
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const liftSampleHelper = (oldSchema, target, config = {}) => {
target.example = oldSchema.example
}
if(target.default === undefined && oldSchema.default !== undefined) {
target.default = oldSchema.default
target.default = oldSchema.defaultfn
}
if(target.enum === undefined && oldSchema.enum !== undefined) {
target.enum = oldSchema.enum
Expand Down Expand Up @@ -81,6 +81,13 @@ const liftSampleHelper = (oldSchema, target, config = {}) => {
}
}
}
if(oldSchema.items) {
if(!target.items) {
target.items = {}
}
target.items = liftSampleHelper(oldSchema.items, target.items, config)
}

return target
}

Expand All @@ -101,6 +108,35 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und
}
if(schema.example !== undefined && schemaToAdd.example !== undefined) {
usePlainValue = true
} else if(schemaToAdd.properties) {
if(!schema.properties) {
schema.properties = {}
}
let props = objectify(schemaToAdd.properties)
for (let propName in props) {
if (!props.hasOwnProperty(propName)) {
continue
}
if ( props[propName] && props[propName].deprecated ) {
continue
}
if ( props[propName] && props[propName].readOnly && !config.includeReadOnly ) {
continue
}
if ( props[propName] && props[propName].writeOnly && !config.includeWriteOnly ) {
continue
}
if(!schema.properties[propName]) {
schema.properties[propName] = props[propName]
if(!schemaToAdd.required && Array.isArray(schemaToAdd.required) && schemaToAdd.required.indexOf(propName) !== -1) {
if(!schema.required) {
schema.required = [propName]
} else {
schema.required.push(propName)
}
}
}
}
}
}
const _attr = {}
Expand Down Expand Up @@ -349,6 +385,7 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und
items.xml = items.xml || schema.xml || {}
items.xml.name = items.xml.name || xml.name
}

if(Array.isArray(items.anyOf)) {
sampleArray = items.anyOf.map(i => sampleFromSchemaGeneric(liftSampleHelper(items, i, config), config, undefined, respectXML))
} else if(Array.isArray(items.oneOf)) {
Expand Down

0 comments on commit b3f81ad

Please sign in to comment.