Skip to content

BUG: Recursive schemas are not handled correctly #186

@valerii15298

Description

@valerii15298

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: [] }],
  },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions