簡體   English   中英

Swagger Codegen:繼承和組合未按預期工作

[英]Swagger Codegen: Inheritance and Composition not working as expected

我有以下簡短的YAML:

# Transaction Request object with minimal information that we need
  Parent:
    required:
  - a
  - b
  - c
properties:
  a:
    type: number
    format: double
  b:
    type: string
  c:
    type: string

# Full transaction
Child:
required:
  - a 
  - b
  - c
allOf:
  - $ref: "#/definitions/Parent"
properties:    
  date: 
    type: string 
    format: date-time
  state: 
    type: string 
    enum: 
      - 1
      - 2
      - 3

在Swagger UI和Editor中,這些對象按我希望的方式顯示: Child繼承了Parentabc字段,並有一些其他字段。

我本來期望:

public class Parent {

  private Double a;
  private String b;
  private String c;

  ...}

 public class Child extends Parent {

 // Superclass fields as well as:
 private Date date;
 private enum State {...};

  ...}

但是,雖然Parent類看起來像預期的那樣,但是Child類卻包含以下內容:

public class Child   {



@Override
public boolean equals(Object o) {
if (this == o) {
  return true;
}
if (o == null || getClass() != o.getClass()) {
  return false;
}
Child child = (Child) o;
return true;
}

... }

甚至缺乏extends 當使用discriminator它可以工作,但是我真的不想要多態性-只是普通繼承。 如何使用Swagger Codegen完成此操作?


相關的pom.xml條目:

            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.2-SNAPSHOT</version>

                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/test.yaml</inputSpec>
                    <language>jaxrs-resteasy</language>
                    <output>${project.build.directory}/generated-sources/payment</output>

                    <configOptions>
                        <sourceFolder>src/java/main</sourceFolder>
                        <dateLibrary>java8</dateLibrary>
                    </configOptions>

                    <groupId>net.product</groupId>
                    <artifactId>product_api</artifactId>
                    <modelPackage>net.product.product_api.model</modelPackage>
                    <invokerPackage>net.product.product_api</invokerPackage>
                    <apiPackage>net.product.product_api</apiPackage>
                </configuration>

                <executions>

                    <execution>
                        <id>generate-server-stubs</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>

                </executions>

            </plugin>
Cat:
  allOf:
  - $ref: "#/definitions/Animal"
  - type: "object"
    properties:
      declawed:
        type: "boolean"
Animal:
  type: "object"
  required:
  - "className"
  discriminator: "className"
  properties:
    className:
      type: "string"
    color:
      type: "string"
      default: "red"

您需要在父類中添加代碼

required:
    - "className"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM