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    ");
  }
}

これは、スプリング ブート ジェネレーターを使用して生成しました。@XmlAttribute名前フィールドの上に注釈が存在することを期待していました。@XmlRootElementまた、クラスのトップになることも期待していました。

何らかの理由で、生成されたコードを現在実行できませんが<MyRequest name="foobar">、エンドポイントに送信すると、そのモデルで解析できないようです。

正しい注釈を生成するために、構成オプションなどを見逃していませんか?

openapi のソースコードを見ると、必要な注釈があります

4

1 に答える 1