I am using the openapi-generator-maven-plugin to generate code for my OpenAPI project. However, I've noticed that when it comes to generating enums representing a polymorphic type, it uses @JsonAdapter instead of @JsonTypeInfo and @JsonSubTypes.
For example, the generated code looks like this:
public class Animal {
@JsonAdapter(TypeEnum.Adapter.class)
public enum TypeEnum {
CAT("CAT"),
DOG("DOG");
private String value;
}
Instead of what I expected, which would include @JsonTypeInfo and @JsonSubTypes annotations for polymorphic deserialization:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true )
@JsonSubTypes( {
@JsonSubTypes.Type( value = Cat.class, name = "CAT" ),
@JsonSubTypes.Type( value = Dog.class, name = "DOG" ),
} )
public class Animal {
Why does the openapi-generator-maven-plugin use @JsonAdapter for enums instead of @JsonTypeInfo and @JsonSubTypes for polymorphic deserialization? Is there a specific configuration or option that I might be missing?
Example Project
I have created an example GitHub project that reproduces this behavior. Feel free to investigate the project to better understand the issue.
The stubs are generated from a YAML definition file:
openapi: '3.0.3'
info:
version: '1.0.0'
title: 'FooService'
components:
schemas:
Zoo:
type: object
properties:
animals:
type: array
items:
$ref: '#/components/schemas/Animal'
Animal:
type: object
required:
- type
properties:
type:
type: string
enum: [CAT, DOG]
discriminator:
propertyName: type
mapping:
CAT: "#/components/schemas/Cat"
DOG: "#/components/schemas/Dog"
Cat:
allOf:
- $ref: "#/components/schemas/Animal"
- type: object
properties:
purrs:
type: boolean
Dog:
allOf:
- $ref: "#/components/schemas/Animal"
- type: object
properties:
barks:
type: boolean
Thank you for your assistance!