asyncapi / java-spring-cloud-stream-template

Java Spring Cloud Stream template for the AsyncAPI Generator
31 stars 33 forks source link

Duplicate variable names #346

Open jmleyman opened 8 months ago

jmleyman commented 8 months ago

When you define a simple component's schemas in your AsynAPI definition file with 2 properties and 2 different names whicth refer to the same object, the generator will generate a class with 2 members with the same names (the same name as the type). The java class doens't compile and the addition @JsonProperty is not usefull (issue linked : @JsonProperty will not get imported in java file

The right class generation must be the same has generate by the Java Spring Template project (https://github.com/asyncapi/java-spring-template/tree/master) whitch generate this class :

import javax.validation.constraints.*;
import javax.validation.Valid;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.List;
import java.util.Objects;
public class MyChannelInfo {
    private @Valid MyReference myPrincipalRef;
    private @Valid MyReference mySecondRef;
    @JsonProperty("myPrincipalRef")
    public MyReference getMyPrincipalRef() {
        return myPrincipalRef;
    }
    public void setMyPrincipalRef(MyReference myPrincipalRef) {
        this.myPrincipalRef = myPrincipalRef;
    }
    @JsonProperty("mySecondRef")
    public MyReference getMySecondRef() {
        return mySecondRef;
    }
    public void setMySecondRef(MyReference mySecondRef) {
        this.mySecondRef = mySecondRef;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MyChannelInfo myChannelInfo = (MyChannelInfo) o;
        return 
            Objects.equals(this.myPrincipalRef, myChannelInfo.myPrincipalRef) &&
            Objects.equals(this.mySecondRef, myChannelInfo.mySecondRef);
    }
    @Override
    public int hashCode() {
        return Objects.hash(myPrincipalRef, mySecondRef);
    }
    @Override
    public String toString() {
        return "class MyChannelInfo {\n" +

                "    myPrincipalRef: " + toIndentedString(myPrincipalRef) + "\n" +
                "    mySecondRef: " + toIndentedString(mySecondRef) + "\n" +
                "}";
    }
    /**
     * 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    ");
    }
}