Swagger 3.0 already has much better support for inheritance and polymorphism compared to 2.0, but codegen, at least for generating java client code, seems to have a few bugs (I'm aware that the tool is still under development, just thought I'd point them out).
The @JsonTypeInfo annotation seems necessary for proper serializing and deserializing when you have multiple subclasses extending a superclass. However, these annotations won't be added unless "--additional-properties jackson=true" is added to the end of the codegen command (java -jar path/to/codegen.jar generate -i source.yaml -l java --additional-properties jackson=true). At least to me, it wasn't immediately obvious that this needed to be added on for the generated java code to have the needed annotations so perhaps it could be noted somewhere?
Once the --additional-properties option was added, the necessary @JsonTypeInfo annotations were put into the superclass model files. However, a openapi spec such as this:
components:
schemas:
superClass:
properties:
type:
type: string
discriminator:
propertyName: type
results in the following annotation:
@JsonTypeInfo(use =
JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property =
"Discriminator{propertyName='type', mapping=null}", visible = true )
instead of the expected
@JsonTypeInfo(use =
JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property =
"type", visible = true )