fix(samples): fix handling of additionalProperties in JSON Schema 2020-12 (#9023)
This change is specific to JSON Schema 2020-12 and OpenAPI 3.1.0. Refs #9022
This commit is contained in:
@@ -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",
|
||||
@@ -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>'
|
||||
|
||||
@@ -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",
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user