Openapi生成器不会生成@ XmlAttribute / @ XmlElement注释

问题描述 投票:0回答:1

我正在摆弄openapi并尝试创建一个使用XML文件的端点。使用openapi创建模型时,似乎我过去常常缺少所有的XML注释。这是我正在使用的openapi.yaml。

openapi: 3.0.1
info:
  version: "1.1"
  title: xml test
  description: some xml test

servers:
  - url: 'http://localhost/:8080'

paths:
  '/test':
    put:
      operationId: testMethodNaming
      requestBody: 
        content:
          'application/xml':
            schema:
              $ref: '#/components/schemas/MyRequest'
      responses:
        '200':
          description: 'OK'

components:
  schemas:
    MyRequest:
      type: object
      properties: 
        name:
          type: string
          xml: 
            attribute: true

MyRequest架构现在是有问题的。请注意,我将name属性声明为XML属性。生成的类看起来像这样:

/**
 * MyRequest
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2019-03-12T15:32:37.070386+01:00[Europe/Berlin]")

public class MyRequest   {
  @JsonProperty("name")
  private String name;

  public MyRequest name(String name) {
    this.name = name;
    return this;
  }

  /**
   * Get name
   * @return name
  */
  @ApiModelProperty(value = "")


  public String getName() {
    return name;
  }

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


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

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

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

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

我使用spring-boot生成器生成了它。我原本期望在名称字段上方出现@XmlAttribute注释。我本来也期望在课堂上会有一个@XmlRootElement

由于某种原因,我现在无法运行生成的代码,但似乎我将<MyRequest name="foobar">发送到端点,它将无法使用该模型解析它。

我是否错过了一些配置选项或任何内容以便生成正确的注释?

查看openapi的源代码,需要注释

java spring-boot openapi openapi-generator
1个回答
0
投票

对我来说,事情变得越来越清晰:现在,OpenAPITools的生成器以及它的父亲SwaggerCodeGen都将json作为主要目标格式。支持Xml是真的,但更多的是作为选项,坦率地说非常糟糕。我最近发现了3个错误:

为了使它工作,我必须自己定制各种mustache templates,以便有正确的xml注释。第一期中描述了解决方法。

重要提示:还要确保激活withXml选项,以便小胡子Pojo模板将生成所需的xml注释。

祝好运。

© www.soinside.com 2019 - 2024. All rights reserved.