OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Generated model contains double JsonTypeName annotation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The attached spec seems to be causing some problems with version 5.0.0 of the openapi-generator-maven-plugin. It creates this model class, which has two JsonTypeName annotations, causing a compilation error:
@JsonPropertyOrder({
First.JSON_PROPERTY_PROP
})
@JsonTypeName("first")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2021-01-28T07:47:45.336926+01:00[Europe/Oslo]")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "discriminator", visible = true)
@JsonTypeName("first")
public class First extends Parent {
...
}
generated-sources/openapi/src/main/java/test/model/First.java:[40,1] com.fasterxml.jackson.annotation.JsonTypeName is not a repeatable annotation type
openapi-generator version
openapi-generator-maven-plugin, version 5.0.0
OpenAPI declaration file content or url
https://gist.github.com/andersflemmen/8e4eddc90b7293fd55f4d75c637b3502
Generation Details
Maven configuration
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<inputSpec>${project.basedir}/openapi.json</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<dateLibrary>java8</dateLibrary>
<feignVersion>10.x</feignVersion>
<java8>true</java8>
</configOptions>
<modelPackage>test.model</modelPackage>
<apiPackage>test.api</apiPackage>
<invokerPackage>test.invoker</invokerPackage>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<library>feign</library>
<addCompileSourceRoot>true</addCompileSourceRoot>
</configuration>
</execution>
</executions>
</plugin>
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 generated-sources/openapi/src/main/java/test/model/First.java output using the linked OpenAPI declaration and the shown openapi-generator-maven-plugin configuration. Start by tracing how the Java generator handles discriminator annotations and compare the duplicate JsonTypeName entries. Done means the generated model compiles with only one JsonTypeName annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100