fix(sample-gen): first oneOf or anyOf should be combined with schema (#6775)

* fix(sample-gen): oneOf and anyOf should be merge into schema

when there was oneOf or anyOf defined it just used the first schema of it to generate the samples.
Now, the first oneOf or anyOf is combined with the schema to generate samples.

* test(sample-gen): oneOf and anyOf should be combined with schema
This commit is contained in:
Mahtis Michel
2021-01-07 20:26:34 +01:00
committed by GitHub
parent 2564625f3d
commit 0f541a1ab0
2 changed files with 121 additions and 14 deletions

View File

@@ -29,6 +29,72 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
})
it("combine first oneOf or anyOf with schema's definitions", function () {
let definition = {
type: "object",
anyOf: [
{
type: "object",
properties: {
test2: {
type: "string",
example: "anyOf"
},
test: {
type: "string",
example: "anyOf"
}
}
}
],
properties: {
test: {
type: "string",
example: "schema"
}
}
}
let expected = {
test: "schema",
test2: "anyOf"
}
expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
definition = {
type: "object",
oneOf: [
{
type: "object",
properties: {
test2: {
type: "string",
example: "oneOf"
},
test: {
type: "string",
example: "oneOf"
}
}
}
],
properties: {
test: {
type: "string",
example: "schema"
}
}
}
expected = {
test: "schema",
test2: "oneOf"
}
expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
})
it("returns object with no readonly fields for parameter", function () {
let definition = {
type: "object",