Reproduction:
import { sample } from "openapi-sampler";
const recursive = {
type: "object",
properties: { human: { $ref: "#/definitions/person" } },
definitions: {
person: {
type: "object",
properties: {
name: { type: "string" },
friend: { $ref: "#/definitions/person" },
friends: { type: "array", items: { $ref: "#/definitions/person" } },
},
required: ["name", "friends"],
},
},
}
const fromSampler = sample(recursive, {}, recursive);
console.log(fromSampler);
Reproduction Invalid Output
{ human: { name: 'string', friend: {}, friends: [ {} ] } }
Which is invalid according to the schema, the friends array should be either empty or contain one valid person and friend field should be either omitted or valid item.
Expected Output
Where friends array is just empty and friend item omitted.
{ human: { name: "string", friends: [] } }
Or where it contains one valid item:
{
human: {
name: "string",
friend: { name: "string", friends: [] },
friends: [{ name: "string", friends: [] }],
},
}
Reproduction:
Reproduction Invalid Output
Which is invalid according to the schema, the
friendsarray should be either empty or contain one valid person andfriendfield should be either omitted or valid item.Expected Output
Where
friendsarray is just empty andfrienditem omitted.Or where it contains one valid item: