在swagger.yaml中定义最终变量

时间:2017-07-05 16:08:36

标签: java variables swagger final swagger-codegen

以某种方式可以用swagger-codegen项目在swagger中定义我在Java代码中得到的东西吗?

public final int XYZ = 2;
public final String ABC = "something_but_not_abc";

所以在我的情况下,我想更改Enums以使用id: 类似的东西:
 public final int BESTOF15 = 2;

这就是我的swagger.yaml文件中定义的样子。

definitions:
  GameMode:
    type: object
    properties:
      id:
        type: integer
        description: id of the gamemode
      name:
        type: string
        description: name of the player
        enum: 
        - bestOf15
        - bestOf100Seconds
        - bestOfDepartment
        - learning
      description:
        type: string
        description: description of the game mode

这个代码将在Java中展示,借助于swagger-codegen项目,如:

public class GameMode   {
  @JsonProperty("id")
  private Integer id = null;

  /**
   * name of the player
   */
  public enum NameEnum {
    BESTOF15("bestOf15"),

    BESTOF100SECONDS("bestOf100Seconds"),

    BESTOFDEPARTMENT("bestOfDepartment"),

    LEARNING("learning");

    private String value;

    NameEnum(String value) {
      this.value = value;
    }

    @Override
    @JsonValue
    public String toString() {
      return String.valueOf(value);
    }

    @JsonCreator
    public static NameEnum fromValue(String text) {
      for (NameEnum b : NameEnum.values()) {
        if (String.valueOf(b.value).equals(text)) {
          return b;
        }
      }
      return null;
    }
  }

  @JsonProperty("name")
  private NameEnum name = null;

  @JsonProperty("description")
  private String description = null;

  public GameMode id(Integer id) {
    this.id = id;
    return this;
  }

   /**
   * id of the gamemode
   * @return id
  **/
  @ApiModelProperty(value = "id of the gamemode")


  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public GameMode name(NameEnum name) {
    this.name = name;
    return this;
  }

   /**
   * name of the player
   * @return name
  **/
  @ApiModelProperty(value = "name of the player")


  public NameEnum getName() {
    return name;
  }

  public void setName(NameEnum name) {
    this.name = name;
  }

  public GameMode description(String description) {
    this.description = description;
    return this;
  }

   /**
   * description of the game mode
   * @return description
  **/
  @ApiModelProperty(value = "description of the game mode")


  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    GameMode gameMode = (GameMode) o;
    return Objects.equals(this.id, gameMode.id) &&
        Objects.equals(this.name, gameMode.name) &&
        Objects.equals(this.description, gameMode.description);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, name, description);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class GameMode {\n");

    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    name: ").append(toIndentedString(name)).append("\n");
    sb.append("    description: ").append(toIndentedString(description)).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    ");
  }
}

0 个答案:

没有答案