Swagger/openAPI无法生成具有扩展ParentClass签名的定义的ChildClass。
我在我的Spring Gradle项目中使用“org.openapi.generator”版本“6.2.1”。
以下是我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 片段
"components": {
"schemas": {
"ParentClass": {
"type": "object",
"properties": {
"parentProperty": {
"type": "string"
}
}
},
"ChildClass": {
"allOf": [
{
"$ref": "#/components/schemas/ParentClass"
},
{
"type": "object",
"properties": {
"childProperty": {
"type": "string"
}
}
}
]
}
}
}
期望结果 应该具有以下定义的 ChildClass
public class ParentClass {
@JsonProperty("parentProperty")
private String parentProperty;
}
public class ChildClass extends ParentClass {
@JsonProperty("childProperty")
private String childProperty;
}
然而生成的结果是一个扁平的ChildClass,其中包含了ParentClass的合并属性,如下所示:
public class ChildClass {
@JsonProperty("childProperty")
private String childProperty;
@JsonProperty("parentProperty")
private String parentProperty;
}
这个子类拥有父类的所有属性(组合),但是两个类之间的关系丢失了,这破坏了代码。我该如何达到预期结果?