[BUG][JAVA] Generated model contains double JsonTypeName annotation
See original GitHub issueBug 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>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:19
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Why discriminator property gets serialized twice?
I Just Ran into the same issue. The problem is with the @JsonTypeInfo annotation on the generated model class. Its being generated as...
Read more >Jackson Annotations - @JsonTypeName - Tutorialspoint
@JsonTypeName is used to set type names to be used for annotated class. Example - @JsonTypeName. import java.io.
Read more >Using @JsonTypeInfo annotation to handle polymorphic types
CLASS) and persist that as JSON property (include = JsonTypeInfo.As.PROPERTY). The property name should be 'className'. Let's run our main ...
Read more >Jackson Annotation Examples - Baeldung
Use Jackson to map custom JSON to any java entity graph with full control over the deserialization process. Read more → ...
Read more >RE: [jackson-user] Binding polymorphic type discriminator as ...
I also have a JsonSubTypes annotation on the same base class with two classes ... However, I am also providing JSON schema validation...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also happens in 5.4.0
We work around it at build time using the replacer Maven plugin like so: