Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid schema generated with circular dependencies - minimal case #1755

Open
radixxko opened this issue Aug 22, 2023 · 0 comments
Open

Invalid schema generated with circular dependencies - minimal case #1755

radixxko opened this issue Aug 22, 2023 · 0 comments
Labels

Comments

@radixxko
Copy link

radixxko commented Aug 22, 2023

Property schema incorrectly referenced when there is a circular reference

Affected version: ts-json-schema-generator@1.3.0

Types

export type Foo = {
    id: number;
    bars: Array<Bar>;
};

export type Broken = Pick<Foo, "id" | "bars">;

export type Bar = {
    broken: Broken;
};

Generated Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Bar": {
      "additionalProperties": false,
      "properties": {
        "broken": {
          "$ref": "#/definitions/Broken"
        }
      },
      "required": [
        "broken"
      ],
      "type": "object"
    },
    "Broken": {
      "additionalProperties": false,
      "properties": {
        "bars": {
          "$ref": "#/definitions/Foo"
        },
        "id": {
          "$ref": "#/definitions/Foo"
        }
      },
      "required": [
        "id",
        "bars"
      ],
      "type": "object"
    },
    "Foo": {
      "additionalProperties": false,
      "properties": {
        "bars": {
          "items": {
            "$ref": "#/definitions/Bar"
          },
          "type": "array"
        },
        "id": {
          "type": "number"
        }
      },
      "required": [
        "id",
        "bars"
      ],
      "type": "object"
    }
  }

Properties id, bars on Broken type are incorrectly referenced to original type instead of fields on type Foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants