fix(xml): render example with oneOf/anyOf (#8206)

* test(e2e): render xml example with oneOf/anyOf
This commit is contained in:
Tim Lai
2022-09-28 14:33:58 -07:00
committed by GitHub
parent 5558bc81f6
commit 4b5d4bda96
3 changed files with 387 additions and 7 deletions

View File

@@ -605,18 +605,19 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec
}
const getXmlSampleSchema = (schema, config, exampleOverride) => {
if (schema && (!schema.xml || !schema.xml.name)) {
schema.xml = schema.xml || {}
if (schema && !schema.xml) {
schema.xml = {}
}
if (schema && !schema.xml.name) {
if (!schema.$$ref && (schema.type || schema.items || schema.properties || schema.additionalProperties)) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- XML example cannot be generated; root element name is undefined -->"
}
if (schema.$$ref) {
let match = schema.$$ref.match(/\S*\/(\S+)$/)
schema.xml.name = match[1]
} else if (schema.type || schema.items || schema.properties || schema.additionalProperties) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- XML example cannot be generated; root element name is undefined -->"
} else {
return null
}
}
return memoizedCreateXMLExample(schema, config, exampleOverride)
}