fix(json-schema-2020-12-samples): skip anyOf and oneOf while merging schemas (#9853)
Refs #9198
This commit is contained in:
@@ -320,10 +320,13 @@ export const sampleFromSchemaGeneric = (
|
||||
}
|
||||
|
||||
if (Array.isArray(contains.anyOf)) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { anyOf, ...containsWithoutAnyOf } = items
|
||||
|
||||
sampleArray.push(
|
||||
...contains.anyOf.map((anyOfSchema) =>
|
||||
sampleFromSchemaGeneric(
|
||||
merge(anyOfSchema, contains, config),
|
||||
merge(anyOfSchema, containsWithoutAnyOf, config),
|
||||
config,
|
||||
undefined,
|
||||
respectXML
|
||||
@@ -331,10 +334,13 @@ export const sampleFromSchemaGeneric = (
|
||||
)
|
||||
)
|
||||
} else if (Array.isArray(contains.oneOf)) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { oneOf, ...containsWithoutOneOf } = items
|
||||
|
||||
sampleArray.push(
|
||||
...contains.oneOf.map((oneOfSchema) =>
|
||||
sampleFromSchemaGeneric(
|
||||
merge(oneOfSchema, contains, config),
|
||||
merge(oneOfSchema, containsWithoutOneOf, config),
|
||||
config,
|
||||
undefined,
|
||||
respectXML
|
||||
@@ -357,10 +363,13 @@ export const sampleFromSchemaGeneric = (
|
||||
}
|
||||
|
||||
if (Array.isArray(items.anyOf)) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { anyOf, ...itemsWithoutAnyOf } = items
|
||||
|
||||
sampleArray.push(
|
||||
...items.anyOf.map((i) =>
|
||||
sampleFromSchemaGeneric(
|
||||
merge(i, items, config),
|
||||
merge(i, itemsWithoutAnyOf, config),
|
||||
config,
|
||||
undefined,
|
||||
respectXML
|
||||
@@ -368,10 +377,13 @@ export const sampleFromSchemaGeneric = (
|
||||
)
|
||||
)
|
||||
} else if (Array.isArray(items.oneOf)) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { oneOf, ...itemsWithoutOneOf } = items
|
||||
|
||||
sampleArray.push(
|
||||
...items.oneOf.map((i) =>
|
||||
sampleFromSchemaGeneric(
|
||||
merge(i, items, config),
|
||||
merge(i, itemsWithoutOneOf, config),
|
||||
config,
|
||||
undefined,
|
||||
respectXML
|
||||
|
||||
@@ -810,6 +810,36 @@ describe("sampleFromSchema", () => {
|
||||
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns array of samples for oneOf with objects", function () {
|
||||
const definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
oneOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
name: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const expected = [{ name: "string" }, { id: "string" }]
|
||||
|
||||
expect(sampleFromSchema(definition)).toStrictEqual(expected)
|
||||
})
|
||||
|
||||
it("returns array of samples for anyOf type", () => {
|
||||
const definition = {
|
||||
type: "array",
|
||||
|
||||
Reference in New Issue
Block a user