fix: don't assign example if an example does not exist (#4365)
fixes #4319
This commit is contained in:
@@ -73,13 +73,13 @@ export const sampleFromSchema = (schema, config={}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(type === "array") {
|
if(type === "array") {
|
||||||
if(Array.isArray(items.anyOf)) {
|
if(Array.isArray(items.anyOf)) {
|
||||||
return items.anyOf.map(i => sampleFromSchema(i, config))
|
return items.anyOf.map(i => sampleFromSchema(i, config))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Array.isArray(items.oneOf)) {
|
if(Array.isArray(items.oneOf)) {
|
||||||
return items.oneOf.map(i => sampleFromSchema(i, config))
|
return items.oneOf.map(i => sampleFromSchema(i, config))
|
||||||
}
|
}
|
||||||
|
|
||||||
return [ sampleFromSchema(items, config) ]
|
return [ sampleFromSchema(items, config) ]
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,9 @@ export const sampleXmlFromSchema = (schema, config={}) => {
|
|||||||
|| enumAttrVal || primitive(props[propName])
|
|| enumAttrVal || primitive(props[propName])
|
||||||
} else {
|
} else {
|
||||||
props[propName].xml.name = props[propName].xml.name || propName
|
props[propName].xml.name = props[propName].xml.name || propName
|
||||||
props[propName].example = props[propName].example !== undefined ? props[propName].example : example[propName]
|
if(props[propName].example === undefined && example[propName] !== undefined) {
|
||||||
|
props[propName].example = example[propName]
|
||||||
|
}
|
||||||
let t = sampleXmlFromSchema(props[propName])
|
let t = sampleXmlFromSchema(props[propName])
|
||||||
if (Array.isArray(t)) {
|
if (Array.isArray(t)) {
|
||||||
res[displayName] = res[displayName].concat(t)
|
res[displayName] = res[displayName].concat(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user