-
-
Notifications
You must be signed in to change notification settings - Fork 530
Types derived for oneOf construct result in TS2502 error #1665
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
Comments
Please try it with version 7 and let us know if the problem still arises. The oneOf discriminator support was completely rewritten and does not use Omit anymore. |
I just checked with |
I encountered the same issue here. I tested it locally with
I believe my issue might be related to this, but I'm uncertain. It would be helpful to confirm if this is indeed the case. |
You need to remove the oneOf from Animal. It is inferred by the inherited discriminator. Please check the unit tests for supported discriminator usages: |
Thank you for your reply. I have already looked for the test when I first encountered this issue. It initially started at #1574. I know we can solve this issue by remove the
|
The JSON Schema Project and the OpenAPI Specification do not restrict the usage of circular references. They pass the problem on to the tooling to be solved (a linter or a validator for example). Details here. If I throw the Animal schema against an OpenAPI validator I am getting a recursion limit error on the first oneOf reference, that is resolved. So this case is an invalid schema. In very rare cases openapi-typescript handles invalid schemas if the case is for example very common. In my opinion this is not true here. |
Many thanks for the clarification, @mzronek . I wonder if the code generator could do better in certain situations. For example manually removing the |
This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed. |
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem. |
Description
Processing the OpenAPI spec of the Mongo Atlas Admin API I found that the
oneOf
construct yields to types that have a cyclic reference that result in TypeScript error TS2502. E.g.:This is the OpenAPI spec of
IngestionSource
:The reason is that in the member types the discriminator property is explicitly omitted, thereby creating the cyclic refernce:
If the
Omit<components["schemas"]["IngestionSource"], "type">
part is omitted ( ;-) ), then the cyclic reference is cut. TypeScript is still able to handle the resulting discriminated union type.Note: If such invalid types are imported from
d.ts
files thentsc
just falls back toany
, loosing all type safetyness.openapi-typescript
6.7.5
Reproduction
Run
openapi-typescript
on the mentioned OpenAPI spec and compile it by tsc.npx @redocly/cli@latest lint
) are unrelatedThe text was updated successfully, but these errors were encountered: