Skip to content

Commit

Permalink
fix(sample-gen): xml attr with media-type example value (#7045)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis-m committed Mar 10, 2021
1 parent 219d886 commit 902241c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/core/plugins/samples/fn.js
Expand Up @@ -307,12 +307,8 @@ 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]
_attr[props[propName].xml.name || propName] = sample[propName]
continue
}
addPropertyToResult(propName, sample[propName])
Expand Down
19 changes: 19 additions & 0 deletions test/unit/core/plugins/samples/fn.js
Expand Up @@ -1774,6 +1774,25 @@ describe("createXMLExample", function () {

expect(sut(definition, {}, expected)).toEqual(expected)
})
it("should use exampleOverride for attr too", () => {
let expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens test=\"probe\">\n</aliens>"
let definition = {
type: "object",
properties: {
test: {
type: "string",
xml: {
attribute: true
}
}
},
xml: {
name: "aliens"
}
}

expect(sut(definition, {}, { test: "probe" })).toEqual(expected)
})
})
})

Expand Down

0 comments on commit 902241c

Please sign in to comment.