-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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] [java] Polymorphy of models broken in v4.3.1 #9615
Comments
I've noticed the same in the Kotlin generator. It seems that something in the core has broken. There are many issues reported that relate to this I think. Is anyone able to see what is going on? It is still very much broken in 5.1.1 since 4.3.0, which has been over a year! |
Ok, an update. In 4.3.1 it added support for the discriminator. After playing around I got the expected result for me by changing the models as follows:
|
Very nice, thanks for your input, @marcdejonge! This seems to work perfectly, I'll try to apply this to my "real" project later. It still seems like a workaround to me, though. Thus I will not yet close this issue. |
I think this is just how the discriminator is supposed to work now. I think it's mostly that the documentation around this is not really clear. Maybe that should be the take away from this. The point is that the discriminator should really be on the base object and not where you wrap it. There is no support for the EXTERNAL_PROPERTY option (from Jackson) for example. |
The problem is that the base class can't always know all the classes that will extend it. In my case, #9756 it isn't even necessary as the base class isn't used for Serialization/Deserialization. But I need the base class for methods that operate on the fields it provides. In my environment we have a "BasePage" object for paged requests. All the services that need paging extend that. BasePage can't possibly know all the services that will support paging as it is in a common library that the services import. This change has made it impossible to support this. |
After I got the Pet model working that @marcdejonge provided in #9615 (comment), I figured out a workaround for my own issue. I had separate yaml files for my schema model classes, and by moving them into the same file as the endpoints under this, it worked for me!!!
Note, I also applied this fix to avoid the extra AllOf classes: #3100 (comment) |
Description
Using the
java
generator, I used to get models where child-classes extend parent classes with version 4.3.0. With version 4.3.1 the child classes do not extend the parent class anymore.openapi-generator version
It's a regression of version 4.3.1. 4.3.0 worked.
OpenAPI declaration file content or url
Generation Details
I run the generator in version 4.3.0 and 4.3.1:
Steps to reproduce
After generating the code in 4.3.0 and 4.3.1, compare
Cat.java
. The generated model of 4.3.0 will containpublic class Cat extends PetBase
while the generated model of 4.3.1 will only containpublic class Cat
(without the inheritance).The text was updated successfully, but these errors were encountered: