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

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: {
    Foo: {
      type: 'object',
      properties: {
        id: { type: 'number' },
        bars: { type: 'array', items: { '$ref': '#/definitions/Bar' } }
      },
      required: [ 'id', 'bars' ],
      additionalProperties: false
    },
    Bar: {
      type: 'object',
      properties: { broken: { '$ref': '#/definitions/Broken' } },
      required: [ 'broken' ],
      additionalProperties: false
    },
    Broken: {
      type: 'object',
      properties: {
        id: { '$ref': '#/definitions/Foo' },
        bars: { '$ref': '#/definitions/Foo' }
      },
      required: [ 'id', 'bars' ],
      additionalProperties: false
    }
  }
}

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
None yet
Projects
None yet
Development

No branches or pull requests

1 participant