1

我有以下简短的 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 和编辑器中,这些对象按我希望的方式显示:Child继承a,bc字段,Parent并具有一些额外的字段。

我本来期望:

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>
4

1 回答 1

1
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"
于 2017-08-03T06:30:07.397 回答