Reputation: 3634
I have the following short 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
In Swagger UI and Editor these objects show up as I wish them to: Child
inherits the a
,b
and c
fields from Parent
and has a few additional ones.
I would have expected:
public class Parent {
private Double a;
private String b;
private String c;
...}
and
public class Child extends Parent {
// Superclass fields as well as:
private Date date;
private enum State {...};
...}
However, while the Parent
class looked as expected, my Child
class consisted of the following:
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;
}
... }
Which lacks even extends
. When using a discriminator
it works, but I don't really want Polymorphism - just plain inheritance. How can I accomplish this with Swagger Codegen?
Relevant pom.xml
entry:
<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>
Upvotes: 2
Views: 4213
Reputation: 11
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"
You need add code at parent class
required:
- "className"
Upvotes: 1