openapi-generator: [BUG][JAVA] Generated model contains double JsonTypeName annotation
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>
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 19
- Comments: 16 (8 by maintainers)
We work around it at build time using the replacer Maven plugin like so:
Also happens in 5.4.0
This is caused by the fact that
@JsonTypeNameis present twice:I suspect this bug has been present for about 10 months. @wing328 with #6995 you added it to
pojo.mustache- about a month after it was added totypeInfoAnnotation.mustachewith #6551.Can confirm on 5.1.0 with
modelNamePrefixas well.Happens with 5.1.0 as well and happens only when I am using the
modelNameSuffixdirective.