-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[BUG] typescript-fetch oneOf doesn't handle discrimination by property. #6513
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Is this issue going to be addressed or is it a won't fix? I have to decide whether to push an API compatibility breaking change for my application, or if I should wait for openapi-generator to fix this before using the generator. |
@keean would you like to implement a fix? |
moreover, you could try the newly refactored https://openapi-generator.tech/docs/generators/typescript |
@macjohnny I'm still running into this issue amongst several others with Using the latest open-api generator as of today: 7.1.0 |
Description
OpenApi generator does not generate valid code for unions discriminated by property name. Unions (oneOf) work correctly when discriminated by a property value, however the generated code seems to try and combine the property lists from all members of the union. If each member of the union have disjoint sets of required properties, then the union is discriminated, and should be generated as such.
openapi-generator version
openapi-generator 4.3.1
OpenAPI declaration file content or url
Command line used for generation
openapi-generator generate -i test.json -g typescript-fetch --additional-properties=typescriptThreePlus --generate-alias-as-model -o test
Steps to reproduce
After generation, the model file for aOrB is:
This fails because A and B both contain 'required' parameters, so they cannot be combined by spreading as above.
Related issues/PRs
There are similar PR, but they don't seem to address exactly the same issue:
#6376 #5202 #4626 #1563 #927
Suggest a fix
The generated functions need to discriminate on properties as well as values, something like:
In the 'if' statements it would test all the required parameters for that member object in the union.
The text was updated successfully, but these errors were encountered: