Open languitar opened 2 years ago
Hi, I'm doing some experimentations with jaxrs-spec generator and I have the same issue.
As a workaround, at the moment I duplicated the mappings value ("dog" in the example above) adding the extension x-discriminator-value to the models (the Dog model in the example above) and I overrided the template to use it instead of the name.
I agree with languitar: I think that some java changes are required to pass the mapping to the pojo template.
PS: the issue happens also on the version 6.0.0 of the openapi-generator.
Hi, just for info: I managed to retrieve the correct mapping by switching to handlebars and accessing them from parent model
In fact, if you remove @JsonTypeName from template everything works fine (Jackson seems to retrieve typeName from parent). You can use pojo.mustache and typeInfoAnnotation.mustache templates from JavaSpring generator.
Bug Report Checklist
Description
https://swagger.io/specification/#discriminator-object describes how the
mapping
key in adiscriminator
object can be used to control the contents of the discriminator field in case of polymorphism. When providing a mapping, instead of the type name the declared map key has to be used per type as the content of the discriminator field.The current code used to generate the
@JsonTypeName
annotation that is used to provide the discriminator value with jackson mapping in many generators (including jaxrs-spec) always uses the data type name, ignoring a potential mapping.For the example from the linked specification:
The generated
Dog
Java class should have the following annotation:@JsonTypeName("dog")
. At the moment, it will always be@JsonTypeName("Dog")
.openapi-generator version
5.3.x
OpenAPI declaration file content or url
Generation Details
nothing fancy, jaxrs-spec with library Quarkus and Jackson mapping is enough to trigger this.
Steps to reproduce
Just generate the code.
Related issues/PRs
Suggest a fix
I suspect there are some actual Java code changes required to compute the intended name from a potentially existing mapping.