-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][JAVA] Generated model contains double JsonTypeName annotation #8559
Comments
Happens with 5.1.0 as well and happens only when I am using the |
Can confirm on 5.1.0 with |
I am getting the same issue with the following config:
|
I get this with 5.1.0 on |
If anyone needs to work around this, here's a workaround. You can season to taste for the files you're seeing this in. 😎
|
We work around it at build time using the replacer Maven plugin like so: <plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<!-- to address https://github.com/OpenAPITools/openapi-generator/issues/8559 -->
<!-- removes the 2nd @JsonTypeName in the below snippet
@JsonTypeName("Classname_allOf")
...some more annotations...
@JsonTypeName("Classname_allOf")
public class ClassnameAllOf {
-->
<execution>
<id>remove-2nd-json-type-name-for-allof-types</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${basedir}/target/generated-sources/openapi</basedir>
<filesToInclude>**/*AllOf.java</filesToInclude>
<regex>true</regex>
<token>@JsonTypeName\(".*_allOf"\)\n\n</token>
<value />
</configuration>
</execution>
</executions>
</plugin> |
Oh, I should mention that I'm seeing this with multiple levels of inheritance - |
Same problem with |
Same problem with |
Same problem with modelNameSuffix and modelNamePrefix in version 5.3.0 |
Same with |
Like @zakamai we do have the same issue with the scala-play-server-template. The generated classes are correct, with the suffix added only once. But all properties have the suffix added twice:
The double suffix happens for all properties (of any type). |
Also happens in 5.4.0 |
We are using the suggested solution from @marcelstoer in 2 of our applications and it works, however with the suggested configuration above it didn't work, but with this one:
|
It's work for me in 6.0.0 I think that this PR fix this issue. /*
* title
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.FirstAllOf;
import org.openapitools.client.model.Parent;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* First
*/
@JsonPropertyOrder({
First.JSON_PROPERTY_PROP
})
@JsonTypeName("first")
@javax.annotation.Generated(value = "com.inditex.aqsw.framework.common.rest.client.codegen.AmigaJavaClientCodegen", date = "2022-07-05T13:28:03.231286+02:00[Europe/Madrid]")
@JsonIgnoreProperties(
value = "discriminator", // ignore manually set discriminator, it will be automatically generated by Jackson during serialization
allowSetters = true // allows the discriminator to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "discriminator", visible = true)
public class First extends Parent {
public static final String JSON_PROPERTY_PROP = "prop";
private String prop;
public First() {
}
public First prop(String prop) {
this.prop = prop;
return this;
}
/**
* Get prop
* @return prop
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonProperty(JSON_PROPERTY_PROP)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public String getProp() {
return prop;
}
@JsonProperty(JSON_PROPERTY_PROP)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setProp(String prop) {
this.prop = prop;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
First first = (First) o;
return Objects.equals(this.prop, first.prop) &&
super.equals(o);
}
@Override
public int hashCode() {
return Objects.hash(prop, super.hashCode());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class First {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" prop: ").append(toIndentedString(prop)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
} |
Bug Report Checklist
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:
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
The text was updated successfully, but these errors were encountered: