fix(sample-gen): should return xml literal example (#6822)

This commit is contained in:
Mahtis Michel
2021-01-13 04:01:44 +01:00
committed by GitHub
parent 25433c4864
commit 59b42bb38f
2 changed files with 50 additions and 1 deletions

View File

@@ -214,6 +214,9 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und
// generate xml sample recursively for array case
if(type === "array") {
if (!Array.isArray(sample)) {
if(typeof sample === "string") {
return sample
}
sample = [sample]
}
const itemSchema = schema
@@ -239,6 +242,10 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und
// generate xml sample recursively for object case
if(type === "object") {
// case literal example
if(typeof sample === "string") {
return sample
}
for (let propName in sample) {
if (!sample.hasOwnProperty(propName)) {
continue
@@ -382,7 +389,9 @@ export const inferSchema = (thing) => {
export const createXMLExample = (schema, config, o) => {
const json = sampleFromSchemaGeneric(schema, config, o, true)
if (!json) { return }
if(typeof json === "string") {
return json
}
return XML(json, { declaration: true, indent: "\t" })
}