0
我有以下的短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
在揚鞭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>
哪個版本是您使用添加代碼? 2.2.2-SNAPSHOT只是正常使用,我用這個2.1.6 YAML https://s3.amazonaws.com/genexuss3test/prueba.yaml – moondaisy
的java,然後使用2.2.1也嘗試過。我沒有嘗試過最新的開發版本,因爲我們真的想用一個穩定版本而不是'SNAPSHOT'來構建我們的存根。不僅如此,當我嘗試輸入'2.2.2-SNAPSHOT'作爲一個版本時,maven也給我一個錯誤,說它的POM丟失了。 – user991710
我只是試着手動將'2.2.2-SNAPSHOT' jar安裝到我的本地倉庫中。然而,用這種方式生成存根與上面的結果完全相同。你能告訴我你用什麼語言/框架生成存根?在此期間,我將使用我的'pom.xml'條目更新我的文章。 – user991710