swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

[Bug] Circularly references when using discriminator

Open alSergey opened this issue 1 year ago • 3 comments

Describe the bug

When using discliminator, cyclic dependencies appear in types. The problem appeared in version 13.0.0, where support was added.

[email protected]

There was no discriminator support in this version, so the problem does not occur.

image

[email protected]

This version added support for discriminator, but it does not work correctly. This causes circular type references.

image

[email protected]

This library supports discriminator and there are no problems with cyclic type references.

image

Reproduction

Open StackBlitz:

alSergey avatar Aug 01 '24 12:08 alSergey

Facing same issue with 13.0.0

MiracleUFO avatar Aug 27 '24 17:08 MiracleUFO

I was facing a similar issue, and narrowed it down to the order of the schemas in the API spec.

The parent schema has to appear BEFORE the schema that references it (with $ref). If the parent appears after, the generated types don't use the "Base" type, and instead inserts the circular reference.

brianguertin avatar Aug 01 '25 17:08 brianguertin

This is what's preventing me from migrating to v13 now that #564 and #1417 have been resolved.

Maybe @smorimoto can help us 🤞.

Thanks in advance!

pablo-olmedo-poex avatar Sep 19 '25 05:09 pablo-olmedo-poex