Open KamasamaK opened 4 years ago
That issue is still reprocucible with version 3.0.27.
One important comment: the line
this.type = this.getClass().getSimpleName()
is not only wrong if enums are used. Without enums (remove the line "enum" : [ "...
from openapi definition), this also prevents the correct type to be set on an object during deserialization (the generated code in JSON.java sees that the type is already set and does not set it to the mapped value)
In fact this seems to be a small change but is a showstopper if polymorphism is used.
I'm getting this in 3.0.39. The only way for me to get around this is to set implementation = String.class
in the schema for the discriminator. I think the fix is to remove the constructor (or at least remove the field assignment from the constructor).
Hi, I am seeing the same issue. I have to manually remove the assignment line from the constructor every time. I am not sure whether this is an issue with swagger and Enum discriminator or I am using it incorrectly. Any progress or ideas on this problem? Thanks
Description
The model for an object with an enum discriminator generates a constructor that causes a compilation error.
The following is an example generated model with some irrelevant code removed.
The statement causing the error is
this.type = this.getClass().getSimpleName()
, which is attempting to assign aString
to aTypeEnum
.Swagger-codegen version
2.4.15 (not a regression)
Swagger declaration file content or url
Full file: https://api.alianza.com/v2/apidocs/swagger.json
Relevant example section
Command line used for generation
Steps to reproduce
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/10196#issuecomment-659673863
Suggest a fix/enhancement
Wrapping
this.getClass().getSimpleName()
with the enum'svalueOf()
fixes the compilation error, but I don't know if this is the proper fix because I don't know what the use of that constructor even is.