fix(sample-gen): allOf, oneOf lifting should consider properties and items (#7041)

This commit is contained in:
Mahtis Michel
2021-03-10 20:18:54 +01:00
committed by GitHub
parent 8405fa0101
commit f9e54a26bf
2 changed files with 206 additions and 5 deletions

View File

@@ -607,6 +607,169 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition, {}, expected)).toEqual(expected)
})
it("should merge properties with anyOf", () => {
const definition = {
type: "object",
properties: {
foo: {
type: "string"
}
},
anyOf: [
{
type: "object",
properties: {
bar: {
type: "boolean"
}
}
}
]
}
const expected = {
foo: "string",
bar: true
}
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should merge array item properties with anyOf", () => {
const definition = {
type: "array",
items: {
type: "object",
properties: {
foo: {
type: "string"
}
},
anyOf: [
{
type: "object",
properties: {
bar: {
type: "boolean"
}
}
}
]
}
}
const expected = [
{
foo: "string",
bar: true
}
]
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should merge properties with oneOf", () => {
const definition = {
type: "object",
properties: {
foo: {
type: "string"
}
},
oneOf: [
{
type: "object",
properties: {
bar: {
type: "boolean"
}
}
}
]
}
const expected = {
foo: "string",
bar: true
}
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should merge array item properties with oneOf", () => {
const definition = {
type: "array",
items: {
type: "object",
properties: {
foo: {
type: "string"
}
},
oneOf: [
{
type: "object",
properties: {
bar: {
type: "boolean"
}
}
}
]
}
}
const expected = [
{
foo: "string",
bar: true
}
]
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should lift items with anyOf", () => {
const definition = {
type: "array",
anyOf: [
{
type: "array",
items: {
type: "boolean"
}
}
]
}
const expected = [
true
]
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should lift items with oneOf", () => {
const definition = {
type: "array",
oneOf: [
{
type: "array",
items: {
type: "boolean"
}
}
]
}
const expected = [
true
]
expect(sampleFromSchema(definition)).toEqual(expected)
})
})
describe("createXMLExample", function () {