Swagger/openAPI is not generating ChildClass with definition having extends ParentClass signature.
I am using "org.openapi.generator" version "6.2.1" in my Spring Gradle project.
Following is the configuration in my build.gradle
generatorName = "spring"
inputSpec = ${rootDir}/open-api/openapi.json
outputDir = file("${buildDir}/open-api/")
modelPackage = "com.example.dto"
configOptions = [
dateLibrary: "java.util.Date", // define our own date classes instead of using the standard ones
hideGenerationTimestamp: "true"
]
`
openapi.json snippet
"components": {
"schemas": {
"ParentClass": {
"type": "object",
"properties": {
"parentProperty": {
"type": "string"
}
}
},
"ChildClass": {
"allOf": [
{
"$ref": "#/components/schemas/ParentClass"
},
{
"type": "object",
"properties": {
"childProperty": {
"type": "string"
}
}
}
]
}
}
}
expected Result should have ChildClass with following definition
public class ParentClass {
@JsonProperty("parentProperty")
private String parentProperty;
}
public class ChildClass extends ParentClass {
@JsonProperty("childProperty")
private String childProperty;
}
However generated result is flat ChildClass with merged properties of ParentClass as follows:
public class ChildClass {
@JsonProperty("childProperty")
private String childProperty;
@JsonProperty("parentProperty")
private String parentProperty;
}
This child class have all properties of parent class (composition) but the relationship between both the classes is lost and breaking code. How can I achieve the expected Result.