Swagger/OpenApi 3.x 组合与继承,同时使用 allOf 扩展 BaseClass

问题描述 投票:0回答:0

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"
             }
             }
        }
    ]
}
}
}

expected Result 应具有具有以下定义的 ChildClass

public class ParentClass {

@JsonProperty("parentProperty")
private String parentProperty;

}

public class ChildClass extends ParentClass {

@JsonProperty("childProperty")
private String childProperty;

}

但是 生成的结果 是具有 ParentClass 合并属性的平面 ChildClass,如下所示:

public class ChildClass {

@JsonProperty("childProperty")
private String childProperty;

@JsonProperty("parentProperty")
private String parentProperty;

}

此子类具有父类(组合)的所有属性,但两个类之间的关系丢失并破坏了代码。我怎样才能达到预期的结果。

swagger openapi extends swagger-codegen openapi-generator-maven-plugin
© www.soinside.com 2019 - 2024. All rights reserved.