OpenAPI codegen gradle 插件忽略failOnUnknownProperties

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

我的 build.gradle.kts 文件中有此配置

tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerateSamApi") {
    generatorName.set("kotlin")
    inputSpec.set("src/main/resources/sam-1.0-patched.yml")
    outputDir.set(samOpenApiGenerateOutputDir)
    modelPackage.set("ch.srg.sam.generated.model")
    modelNameSuffix.set("Dto")
    generateModelDocumentation.set(false)
    configOptions.set(
        mapOf(
            Pair("dateLibrary", "java8"),
            Pair("serializationLibrary", "jackson"),
            Pair("enumPropertyNaming", "UPPERCASE"),
            Pair("failOnUnknownProperties", "false"),
        ),
    )
}
tasks.getByName("openApiGenerateSamApi").dependsOn("kspKotlin")

但是生成的序列化程序不包含 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES:

object Serializer {
    @JvmStatic
    val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
        .findAndRegisterModules()
        .setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
        .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
}

即使我将failOnUnknownProperties设置为true也没有效果。 问题是,一旦服务将字段添加到其域模型中,客户端就毫无用处

kotlin gradle jackson openapi-generator
1个回答
0
投票

最后我只使用标准的序列化库,即GSON。有了它,就不存在未知属性的问题。

configOptions.set(
    mapOf(
        Pair("dateLibrary", "java8"),
        Pair("enumPropertyNaming", "UPPERCASE"),
    ),
)
© www.soinside.com 2019 - 2024. All rights reserved.