Mapping element doesn't appear to be supported in io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.3 plugin.
I have the following swagger (extract):
Vehicle:
type: object
discriminator:
propertyName: type
mapping:
car: '#/components/schemas/Car'
truck: '#/components/schemas/Truck'
properties:
model:
type: string
...
And the following class is generated:
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2018-12-12T10:48:45.405+01:00[Europe/Paris]")@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "Discriminator{propertyName='type', mapping={car=#/components/schemas/Car, truck=#/components/schemas/Truck}}", visible = true )
@JsonSubTypes({
@JsonSubTypes.Type(value = Car.class, name = "Car"),
@JsonSubTypes.Type(value = Truck.class, name = "Truck"),
})
public class Vehicle {
Whereas, I would expect to find my swagger mappings in the name attribute, something like:
@JsonSubTypes.Type(value = Car.class, name = "car"),
@JsonSubTypes.Type(value = Truck.class, name = "truck"),
Specification link:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#discriminatorObject
Sample project showing the issue: https://github.com/gonzalad/swagger-samples/tree/swagger-openapi3-inheritance/client
3.0.3
https://gist.github.com/gonzalad/1953b3c504240112bfc11241eb5afa38
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.yml</inputSpec>
<language>java</language>
<configOptions>
<library>resttemplate</library>
<!--
<sourceFolder>src/gen/java/main</sourceFolder>
-->
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Thanks,
Adrian
Note that you can get it working with using the vendor extension x-discriminator-value on the sub type.
Most helpful comment
Note that you can get it working with using the vendor extension
x-discriminator-valueon the sub type.