diff --git a/src/core/plugins/samples/fn.js b/src/core/plugins/samples/fn.js index a5312b9a..e7d8d47f 100644 --- a/src/core/plugins/samples/fn.js +++ b/src/core/plugins/samples/fn.js @@ -202,6 +202,10 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und if (schema && props[propName] && props[propName].writeOnly && !includeWriteOnly) { continue } + if (schema && props[propName] && props[propName].xml && props[propName].xml.attribute && !(example && example[propName])) { + _attr[props[propName].xml.name || propName] = sample[propName] + continue + } if (schema && props[propName] && props[propName].xml && props[propName].xml.attribute) { _attr[props[propName].xml.name || propName] = example[propName] continue diff --git a/test/e2e-cypress/static/documents/bugs/6627.yaml b/test/e2e-cypress/static/documents/bugs/6627.yaml new file mode 100644 index 00000000..67fc0736 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/6627.yaml @@ -0,0 +1,41 @@ +openapi: 3.0.1 +info: + title: XML array schema with array-level example + version: 1.0.0 + +paths: + /users: + get: + responses: + "200": + description: '' + content: + application/xml: + schema: + $ref: '#/components/schemas/Users' + +components: + schemas: + Users: + type: array + example: + - id: 123 + name: bob + - id: 456 + name: jane + xml: + name: Users + wrapped: true + items: + type: object + xml: + name: User + properties: + id: + type: integer + xml: + attribute: true + name: + type: string + xml: + attribute: true diff --git a/test/e2e-cypress/tests/bugs/6627.js b/test/e2e-cypress/tests/bugs/6627.js new file mode 100644 index 00000000..716b21fa --- /dev/null +++ b/test/e2e-cypress/tests/bugs/6627.js @@ -0,0 +1,11 @@ +describe("#6627: XML example when defined as array", () => { + it("should render xml like json", () => { + const expected = "\n\n\t\n\t\n\t\n\t\n" + cy + .visit("/?url=/documents/bugs/6627.yaml") + .get("#operations-default-get_users") + .click() + .get(".microlight") + .contains(expected) + }) +})