swagger codegen spring boot缺少XmlRootElement和XmlElement

时间:2016-11-10 05:12:17

标签: swagger swagger-2.0 swagger-codegen

我使用以下命令使用swagger生成弹出启动代码

java -jar ./swagger-codegen-cli-2.2.1.jar generate \
        -i /swagger.yaml \
        -o ./swagger-demo-restful \
        -l spring

使用swagger.yaml中的以下定义:

definitions:
  AlertDef:
    type: object
    properties:
      alertName:
        type: string
        description: name of the alert
        xml:
          name: AlertName

生成的代码如下:

package io.swagger.model;

import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * AlertDef
 */
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-11-10T13:06:05.500+08:00")

public class AlertDef   {
  private String alertName = null;

  public AlertDef alertName(String alertName) {
    this.alertName = alertName;
    return this;
  }

   /**
   * name of the alert
   * @return alertName
  **/
  @ApiModelProperty(value = "name of the alert")
  public String getAlertName() {
    return alertName;
  }

  public void setAlertName(String alertName) {
    this.alertName = alertName;
  }
  // toString, hashcode, etc...
}

但为了使restful API成功返回XML,需要将@XmlRootElement(name = "AlertDef")添加到类和@XmlElement到每个set方法。

yaml文件中是否缺少某些内容或swagger codegen暂时不支持它?

0 个答案:

没有答案