Skip to content

Commit

Permalink
test(sample-gen): added missing tests for allOf, oneOf lifting
Browse files Browse the repository at this point in the history
Signed-off-by: mathis-m <mathis.michel@outlook.de>
  • Loading branch information
mathis-m committed Mar 6, 2021
1 parent 032b6bc commit 698e1cd
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions test/unit/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,128 @@ 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)
})
})

describe("createXMLExample", function () {
Expand Down

0 comments on commit 698e1cd

Please sign in to comment.