Skip to content
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

[Spring] @JsonTypeInfo property not set to Discriminator propertyName #103

Closed
atgabe opened this issue Jun 18, 2018 · 1 comment
Closed

Comments

@atgabe
Copy link
Contributor

atgabe commented Jun 18, 2018

Using Spring codegen on a schema with a discriminator property populates the @JsonTypeInfo annotation with the Discriminator class represented as a string, instead of the propertyName itself.

For example, this schema:

Example:
      type: object
      required:
        - baseType
      discriminator:
        propertyName: baseType
      properties:
        baseType:
          type: string
        otherProp:
          type: string

will generate this class:

/**
 * Example
 */
@Validated

@javax.annotation.Generated(value = "io.swagger.codegen.languages.java.SpringCodegen", date = "2018-06-18T16:55:52.608-04:00[America/New_York]")

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "Discriminator{propertyName='baseType', mapping=null}", visible = true )
@JsonSubTypes({
  
})

public class Example   {

  @JsonProperty("baseType")
  private String baseType = null;
  
  @JsonProperty("otherProp")
  private String otherProp = null;
  
  public Example baseType(String baseType) {
    this.baseType = baseType;
    return this;
  }
 

  /**
   * Get baseType
   * @return baseType
  **/
 
  @ApiModelProperty(required = true, value = "")
  @NotNull
  public String getBaseType() {
    return baseType;
  }

  public void setBaseType(String baseType) {
    this.baseType = baseType;
  }

  public Example otherProp(String otherProp) {
    this.otherProp = otherProp;
    return this;
  }
  
  /**
   * Get otherProp
   * @return otherProp
  **/
 
  @ApiModelProperty(value = "")
  public String getOtherProp() {
    return otherProp;
  }

  public void setOtherProp(String otherProp) {
    this.otherProp = otherProp;
  }

  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Example example = (Example) o;
    return Objects.equals(this.baseType, example.baseType) &&
        Objects.equals(this.otherProp, example.otherProp);
  }

  @Override
  public int hashCode() {
    return Objects.hash(baseType, otherProp);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Example {\n");
    
    sb.append("    baseType: ").append(toIndentedString(baseType)).append("\n");
    sb.append("    otherProp: ").append(toIndentedString(otherProp)).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    ");
  }
}

The point of interest here is with the line:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "Discriminator{propertyName='baseType', mapping=null}", visible = true )

which should read:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "baseType", visible = true )
@wvitte
Copy link

wvitte commented Jan 9, 2019

Any reason, why this was not added to mustache templates for JavaSpring generators? I see mustache as default templates for spring and scala codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants