Skip to content

Commit

Permalink
toggle {CDATA: true} to {x-cdata: true}
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNorthMemory committed Oct 11, 2018
1 parent d79c82e commit 50a4b4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const sampleXmlFromSchema = (schema, config={}) => {

if (additionalProperties) {
value = additionalProperties === true || !Object.getOwnPropertyNames(additionalProperties).length ? "Anything can be here" : primitive(additionalProperties)
value = (additionalProperties.xml || xml || {}).CDATA ? {_cdata: value} : value
value = (additionalProperties.xml || xml || {})['x-cdata'] ? {_cdata: value} : value
res[displayName].push({additionalProp: value})
}

Expand All @@ -257,7 +257,7 @@ export const sampleXmlFromSchema = (schema, config={}) => {
value = primitive(schema)
}

res[displayName] = _attr ? xml.CDATA ? {_attr: _attr, _cdata: value} : [{_attr: _attr}, value] : value
res[displayName] = _attr ? xml['x-cdata'] ? {_attr: _attr, _cdata: value} : [{_attr: _attr}, value] : value

return res
}
Expand Down
28 changes: 14 additions & 14 deletions test/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns value wrapped by `CDATA` when passing {CDATA: true}", function () {
it("returns value wrapped by `CDATA` when passing {'x-cdata': true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<notagname><![CDATA[foo&bar 1<2]]></notagname>"
var definition = {
type: "string",
example: "foo&bar 1<2",
xml: {
CDATA: true
'x-cdata': true
}
}

Expand Down Expand Up @@ -916,14 +916,14 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns array with example values wrapped by `CDATA` when passing {CDATA: true}", function () {
it("returns array with example values wrapped by `CDATA` when passing {'x-cdata': true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal><![CDATA[foo&bar]]></animal>\n\t<animal><![CDATA[1<2]]></animal>\n</animals>"
var definition = {
type: "array",
items: {
type: "string",
xml: {
CDATA: true,
'x-cdata': true,
name: "animal"
}
},
Expand Down Expand Up @@ -1335,21 +1335,21 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns object with example value wrapped by `CDATA` when passing {CDATA: true}", function () {
it("returns object with example value wrapped by `CDATA` when passing {'x-cdata': true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bob>\n\t<foo><![CDATA[&bar]]></foo>\n\t<bar><![CDATA[<2]]></bar>\n</bob>"
var definition = {
type: "object",
properties: {
foo: {
type: "string",
xml: {
CDATA: true
'x-cdata': true
}
},
bar:{
type: "string",
xml: {
CDATA: true
'x-cdata': true
}
}
},
Expand All @@ -1365,20 +1365,20 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns object with 2 properties those values wrapped by `CDATA` when passing {CDATA: true}", function () {
it("returns object with 2 properties those values wrapped by `CDATA` when passing {'x-cdata': true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bob>\n\t<foo><![CDATA[string]]></foo>\n\t<bar><![CDATA[string]]></bar>\n</bob>"
var definition = {
properties: {
foo: {
type: "string",
xml: {
CDATA: true
'x-cdata': true
}
},
bar: {
type: "string",
xml: {
CDATA: true
'x-cdata': true
}
}
},
Expand All @@ -1390,27 +1390,27 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns object with additional props equals `true` and those values wrapped by `CDATA` when the defs passing {CDATA: true}", function () {
it("returns object with additional props equals `true` and those values wrapped by `CDATA` when the defs passing {'x-cdata': true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<additionalProp><![CDATA[Anything can be here]]></additionalProp>\n</animals>"
var definition = {
additionalProperties: true,
xml: {
name: "animals",
wrapped: true,
CDATA: true
'x-cdata': true
}
}

expect(sut(definition)).toEqual(expected)
})

it("returns object with additional props those values wrapped by `CDATA` when passing {CDATA: true}", function () {
it("returns object with additional props those values wrapped by `CDATA` when passing {'x-cdata': true}", function () {
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<additionalProp><![CDATA[string]]></additionalProp>\n</animals>"
var definition = {
additionalProperties: {
type: "string",
xml: {
CDATA: true
'x-cdata': true
}
},
xml: {
Expand Down

0 comments on commit 50a4b4c

Please sign in to comment.