Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export const sampleFromSchemaGeneric = (
return res
}

if (isBooleanJSONSchema(additionalProperties)) {
if (isBooleanJSONSchema(additionalProperties) && additionalProperties) {
if (respectXML) {
res[displayName].push({ additionalProp: "Anything can be here" })
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,67 @@ describe("sampleFromSchema", () => {

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

it("should handle additionalProperties", () => {
const definition = {
type: "object",
additionalProperties: {
type: "string",
},
properties: {
foo: {
type: "string",
},
},
}

const expected = {
foo: "string",
additionalProp1: "string",
additionalProp2: "string",
additionalProp3: "string",
}

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

it("should handle additionalProperties=true", () => {
const definition = {
type: "object",
additionalProperties: true,
properties: {
foo: {
type: "string",
},
},
}

const expected = {
foo: "string",
additionalProp1: {},
}

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

it("should handle additionalProperties=false", () => {
const definition = {
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
},
},
}

const expected = {
foo: "string",
}

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

it("should ignore minProperties if cannot extend object", () => {
const definition = {
type: "object",
Expand Down Expand Up @@ -2618,6 +2679,25 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns object with additional props =false", function () {
let expected =
'<?xml version="1.0" encoding="UTF-8"?>\n<animals>\n\t<dog>string</dog>\n</animals>'
let definition = {
type: "object",
properties: {
dog: {
type: "string",
},
},
additionalProperties: false,
xml: {
name: "animals",
},
}

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

it("returns object with 2 properties with no type passed but properties", function () {
const expected =
'<?xml version="1.0" encoding="UTF-8"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>'
Expand Down
80 changes: 80 additions & 0 deletions test/unit/core/plugins/samples/fn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,68 @@ describe("sampleFromSchema", () => {

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


it("should handle additionalProperties", () => {
const definition = {
type: "object",
additionalProperties: {
type: "string",
},
properties: {
foo: {
type: "string",
},
},
}

const expected = {
foo: "string",
additionalProp1: "string",
additionalProp2: "string",
additionalProp3: "string",
}

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

it("should handle additionalProperties=true", () => {
const definition = {
type: "object",
additionalProperties: true,
properties: {
foo: {
type: "string",
},
},
}

const expected = {
foo: "string",
additionalProp1: {},
}

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

it("should handle additionalProperties=false", () => {
const definition = {
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
},
},
}

const expected = {
foo: "string",
}

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

it("should ignore minProperties if cannot extend object", () => {
const definition = {
type: "object",
Expand Down Expand Up @@ -2149,6 +2211,24 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})

it("returns object with additional props =false", function () {
let expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<dog>string</dog>\n</animals>"
let definition = {
type: "object",
properties: {
dog: {
type: "string"
}
},
additionalProperties: false,
xml: {
name: "animals"
}
}

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

it("returns object with 2 properties with no type passed but properties", function () {
let expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>"
let definition = {
Expand Down