-
Notifications
You must be signed in to change notification settings - Fork 96
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
OpenAPI Generator generates classes that can't build for models with two (or more) levels of inheritance and a discriminator #1206
Comments
Ok, I'll fix it on the weekend |
altro3
added a commit
to altro3/micronaut-openapi
that referenced
this issue
Sep 17, 2023
altro3
added a commit
to altro3/micronaut-openapi
that referenced
this issue
Sep 21, 2023
altro3
added a commit
to altro3/micronaut-openapi
that referenced
this issue
Sep 22, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
When the OpenAPI Generator generates classes for a OpenAPI definition with a model with two (or more) levels of inheritance and using a discriminator, the generated classes should build, and the discriminator field should not be part of the constructor parameters in any of the generated classes.
Actual Behaviour
The sub-class (BasicBookInfo in my example below) is generated correctly, but the sub-sub-class (DetailedBookInfo in my example below) has the discriminator field as part of the constructor parameters and calls it's parent's (BasicBookInfo) constructor with incorrect parameters.
This means the generated classes can't build.
I think the problem is related to the fix done in this issue, since in version 4.0.3 of the OpenAPI plugin, the discriminator was part of all constructors, and the generated classes could build even with two levels of inheritance.
I think it is preferable, if the discriminator is not part of the constructor of any generated classes, as it is not required, and there's actually a bug in Micronaut Serialization, that causes the discriminator field to be output twice in the JSON when serializing, if it is set in the model.
But if it is not possible to both get this and classes that build, I suppose classes that build are preferable 🙂
Steps To Reproduce
DetailedBookInfo
. The parametername
is missing in the call to the super class. AlsoTypeEnum type
should not be a parameter inDetailedBookInfo
's constructor signature.build.gradle.kts
(id("io.micronaut.openapi") version "4.0.3"
) and see that now it builds.SerdeWithDiscriminatorTest
due to this unrelated bug, that was fixed in version 4.1.0.Environment Information
OS: MacOS
JDK: 17
Example Application
https://github.com/runenielsen/discriminatorconstructorbug
Version
4.1.0
The text was updated successfully, but these errors were encountered: