我有以下简短的 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
,b
和c
字段,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>