Bug Report Checklist
Description
https://swagger.io/specification/#discriminator-object describes how the mapping key in a discriminator 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:
MyResponseType:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Lizard'
- $ref: 'https://gigantic-server.com/schemas/Monster/schema.json'
discriminator:
propertyName: petType
mapping:
dog: '#/components/schemas/Dog'
monster: 'https://gigantic-server.com/schemas/Monster/schema.json'
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
components:
schemas:
MyResponseType:
oneOf:
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: petType
mapping:
dog: '#/components/schemas/Dog'
Dog:
type: object
properties:
test:
type: string
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.
Bug Report Checklist
Description
https://swagger.io/specification/#discriminator-object describes how the
mappingkey in adiscriminatorobject 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
@JsonTypeNameannotation 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
DogJava 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.