swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Java] error: <identifier> expected if model has property with name 'on'

Open ikovalyov opened this issue 3 years ago • 5 comments

Description

Invalid code is generated by swagger swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.35")

Swagger-codegen version

3.0.35

Swagger declaration file content or url

Having a schema

components:
  schemas:
    Test:
      properties:
        on:
          type: string
          enum:
            - score
            - updated_at

This java code is generated:

public class Test {
  /**
   * Gets or Sets true
   */
  public enum TrueEnum {
    SCORE("score"),
    UPDATED_AT("updated_at");

    private String value;

    TrueEnum(String value) {
      this.value = value;
    }
    @JsonValue
    public String getValue() {
      return value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }
    @JsonCreator
    public static TrueEnum fromValue(String input) {
      for (TrueEnum b : TrueEnum.values()) {
        if (b.value.equals(input)) {
          return b;
        }
      }
      return null;
    }

  }  @JsonProperty("true")
  private TrueEnum true = null;

  public Test true(TrueEnum true) {
    this.true = true;
    return this;
  }

   /**
   * Get true
   * @return true
  **/
  @Schema(description = "")
  public TrueEnum getTrue() {
    return true;
  }

  public void setTrue(TrueEnum true) {
    this.true = true;
  }


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Test test = (Test) o;
    return Objects.equals(this.true, test.true);
  }

  @Override
  public int hashCode() {
    return Objects.hash(true);
  }


  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Test {\n");
    
    sb.append("    true: ").append(toIndentedString(true)).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(java.lang.Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }

}

Renaming property on to something else solvess issue

ikovalyov avatar Sep 19 '22 09:09 ikovalyov

This error does not appear in 3.0.34

ikovalyov avatar Sep 19 '22 13:09 ikovalyov

Still happens in 3.0.40

ikovalyov avatar Feb 02 '23 08:02 ikovalyov

Still happens in 3.0.41

ikovalyov avatar Mar 21 '23 10:03 ikovalyov

Still happens in 3.0.46.

mocanu-razvan avatar Sep 05 '23 08:09 mocanu-razvan

Still happens in 3.0.52

grafster avatar Jan 26 '24 12:01 grafster