Open mvettosi opened 5 months ago
My team and me were also observing progress on the mentioned PR very closely over the past months. We'd really appreciate a fix for this issue.
I can confirm the same issue. It would be nice to have anyOf
and oneOf
supported asap.
Yeah same, our team currently use typescript-nestjs generator (not Kotlin), but the result is the same, looks like if we have anyOf
it just use the last type.
Description
When describing an array of values with the keyword
anyOf
, all the models seem correctly generated but only the last one in the list is actually used.openapi-generator version
Also reproducible with:
OpenAPI declaration file content or url
Here is a minimal example that reproduces the issue: https://gist.github.com/mvettosi/d646be95fd43e732cd5dcce680b60597
Generation Details
The file
MyapiPut200ResponseIncludedInner.kt
correctly imports the models listed byanyOf
(Cat.kt
andDog.kt
), also their individualtype
enums are merged in here as one would reasonably expect. However, theattributes
field is not a merge ofCat
andDog
, nor a superclass of either, but it's hardcoded to beDog
, making it impossible to access the fields that are specific toCat
.Steps to reproduce
Simply run
Related issues/PRs
I saw this PR which was supposed to address the
anyOf
implementation, but it was recently closed without an explanation: https://github.com/OpenAPITools/openapi-generator/pull/12924 Moreover, I downloaded and compiled the original work from https://github.com/vfouqueron/openapi-generator/tree/release/vf-7.0.x and the same error seems to occur.I tried to apply the workaround suggested here: https://stackoverflow.com/a/67197819/21581836 However, the result didn't compile despite various attempts to fix from my side by changing the template files.
Suggest a fix
I'm not sure how the keyword is supposed to be implemented by kotlin currently, I can only assume an interface should be generated that both
Cat
andDog
should implement, and that some code in the generated client should figure out which actual model to use based on the discriminator.Alternatively, I would personally be very happy with a simpler approach like a single model that merges all field from all possible models listed, so that they can all be accessed.
Any workaround, that includes either spec or template manipulation would be very welcome, too! I really need to be unblocked by this.
Thanks!