fixes for XML render

This commit is contained in:
Anna Bodnia
2017-03-22 16:14:20 +02:00
parent bfa7214cdf
commit 4ebe2273da
7 changed files with 117 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"version":3,"file":"swagger-ui-bundle.js","sources":["webpack:///swagger-ui-bundle.js"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AAoOA;;;;;;AAoIA;AAm7FA;AAwtCA;AAg0IA;;;;;AAkxBA;AA+7IA;AAi2GA;AA43FA;AAqoFA;AA4pFA;AA+9CA;AA+gDA;AAwrCA;AAu0EA;AAs4HA;;;;;;;;;;;;;;AA8kHA;AAyoIA;AAkuJA;AAilHA;AA4kGA;AAwkEA;AAs3DA;AAovDA;AA0tBA;AA+pGA;;;;;;AAseA;AAimGA;AA44EA;;;;;AAoGA;AA2qFA;AAm2CA;AAmvDA;AAwtCA;AAuiEA;AA29FA;;;;;;;;;AA00BA;AA2zIA;AAk4DA","sourceRoot":""} {"version":3,"file":"swagger-ui-bundle.js","sources":["webpack:///swagger-ui-bundle.js"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AAoOA;;;;;;AAoIA;AAm7FA;AAwtCA;AA+yIA;AA4qHA;AA0xHA;AA8pGA;AAs8EA;AA8hHA;AA0jIA;AAwRA;;;;;AA4sCA;AAmwJA;;;;;;;;;;;;;;AAgtEA;AAyoIA;AAiuJA;AA8kHA;AAykGA;AAskEA;AAy3DA;AA+vDA;AAisBA;AA+qGA;;;;;;AA+eA;AAm3FA;AAw+CA;AAwgDA;AA4yCA;AAgyEA;AA0iHA;;;;;AA2oDA;AA2qFA;AAm2CA;AAmvDA;AAwtCA;AAsiEA;AA29FA;;;;;;;;;AA20BA;AA2zIA;AAk4DA;AA6/EA","sourceRoot":""}

File diff suppressed because one or more lines are too long

2
dist/swagger-ui.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"version":3,"file":"swagger-ui.js","sources":["webpack:///swagger-ui.js"],"mappings":"AAAA;AAqnGA;AAg2HA;AA6+FA;AAgqCA;AAi+BA;AAyvCA;AA04BA","sourceRoot":""} {"version":3,"file":"swagger-ui.js","sources":["webpack:///swagger-ui.js"],"mappings":"AAAA;AAqnGA;AAg3HA;AA6+FA;AAgqCA;AAi+BA;AAyvCA;AA04BA","sourceRoot":""}

View File

@@ -127,8 +127,12 @@ export const sampleXmlFromSchema = (schema, config={}) => {
if (xml.wrapped) { if (xml.wrapped) {
res[displayName] = [] res[displayName] = []
if (Array.isArray(defaultValue)) { if (Array.isArray(example)) {
example.forEach((v)=>{
items.example = v
res[displayName].push(sampleXmlFromSchema(items, config))
})
} else if (Array.isArray(defaultValue)) {
defaultValue.forEach((v)=>{ defaultValue.forEach((v)=>{
items.default = v items.default = v
res[displayName].push(sampleXmlFromSchema(items, config)) res[displayName].push(sampleXmlFromSchema(items, config))
@@ -145,14 +149,20 @@ export const sampleXmlFromSchema = (schema, config={}) => {
let _res = [] let _res = []
if (Array.isArray(defaultValue)) { if (Array.isArray(example)) {
example.forEach((v)=>{
items.example = v
_res.push(sampleXmlFromSchema(items, config))
})
return _res
} else if (Array.isArray(defaultValue)) {
defaultValue.forEach((v)=>{ defaultValue.forEach((v)=>{
items.default = v items.default = v
_res.push(sampleXmlFromSchema(items, config)) _res.push(sampleXmlFromSchema(items, config))
}) })
return _res return _res
} }
return sampleXmlFromSchema(items, config) return sampleXmlFromSchema(items, config)
} }
} }
@@ -176,7 +186,13 @@ export const sampleXmlFromSchema = (schema, config={}) => {
} 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] props[propName].example = props[propName].example !== undefined ? props[propName].example : example[propName]
res[displayName].push(sampleXmlFromSchema(props[propName])) let t = sampleXmlFromSchema(props[propName])
if (Array.isArray(t)) {
res[displayName] = res[displayName].concat(t)
} else {
res[displayName].push(t)
}
} }
} }
} }

View File

@@ -396,7 +396,7 @@ describe("createXMLExample", function () {
}) })
it("returns array with default values with wrapped=true", function () { it("returns array with default values with wrapped=true", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>one</animal>\n</animals>" var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
var definition = { var definition = {
items: { items: {
"enum": ["one", "two"], "enum": ["one", "two"],
@@ -405,6 +405,7 @@ describe("createXMLExample", function () {
name: "animal" name: "animal"
} }
}, },
"default": ["1", "2"],
xml: { xml: {
wrapped: true, wrapped: true,
name: "animals" name: "animals"
@@ -413,8 +414,53 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected) expect(sut(definition)).toEqual(expected)
}) })
it("returns array with example values with ", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
var definition = {
type: "object",
properties: {
"animal": {
"type": "array",
"items": {
"type": "string"
},
"example": [
"1",
"2"
]
}
},
xml: {
name: "animals"
}
}
expect(sut(definition)).toEqual(expected)
})
it("returns array with example values with wrapped=true", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
var definition = {
type: "array",
items: {
type: "string",
xml: {
name: "animal"
}
},
"example": [ "1", "2" ],
xml: {
wrapped: true,
name: "animals"
}
}
expect(sut(definition)).toEqual(expected)
}) })
})
describe("object", function () { describe("object", function () {
it("returns object with 2 properties", function () { it("returns object with 2 properties", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>" var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>"