swagger-api / swagger-api/swagger-codegen
[Java] Support inheritance (OAS3: discriminator/mapping element)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
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
Swagger-codegen version
3.0.3
Swagger declaration file content or url
https://gist.github.com/gonzalad/1953b3c504240112bfc11241eb5afa38
Command line used for generation
<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>
Steps to reproduce
- run swaggercodegen on the linked swagger.yml file
Thanks,
Adrian
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the linked sample project's swagger.yml and the swagger-codegen-maven-plugin, then trace discriminator handling through JavaClientCodegen. Done means the generated Vehicle class uses the mapping keys "car" and "truck" as the JsonSubTypes name values and retains the discriminator property name "type".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100