【问题标题】:Openapi generator: Add import class to generated modelOpenapi 生成器:将导入类添加到生成的模型
【发布时间】:2022-11-09 01:37:19
【问题描述】:

我正在使用 Openapi 生成器(5.4.0),带有 spring(生成器名称)和 gradle,我正在尝试将导入添加到生成的模型中。

对于 api 规范中的特定字段,我添加了:

 x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonFormat ...."

这可行,但是我不想完全限定它,并添加了 com.fasterxml.jackson.annotation.JsonFormat 导入。

我尝试将 typeMappings 添加到 genratedCode 任务,但这不起作用。

importMappings = [
            'JsonFormat'    : 'com.fasterxml.jackson.annotation.JsonFormat'
    ]

更新: 我可以将 model.mustache 模板添加到项目中,并添加导入。 IE

{{#useBeanValidation}}
...
import com.fasterxml.jackson.annotation.JsonFormat;
...
{{/useBeanValidation}}

有任何想法吗?更好的方法。 谢谢。

【问题讨论】:

  • 您是否正在寻找 OOTB 解决方案(如果忘记了将内容放入 x-class-extra-annotation 的“选项”,openapi 生成器似乎不支持您想要的)或询问如何改进 mustache 模板?

标签: java spring-boot openapi-generator


【解决方案1】:

没有生产就绪的解决方案(还没有!) 如果您不渴望此功能,请等待相关问题的接受和 PR 到最近的版本之一。 https://github.com/OpenAPITools/openapi-generator/issues/13938 它将允许使用所需的自定义 x-spring-constraint: @MyAnnotation(value = 1, message = "nice") (或 x-java-constraint) 扩展与 configOption customValidationAnnotationsPackages="my.custom.package.MyAnotaion;my.other.package.*"

否则,参考https://bartko-mat.medium.com/openapi-generator-to-spring-boot-with-custom-java-validations-623381df9215手工解决方案教程

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-27
    • 2023-01-12
    • 2020-12-19
    • 2021-07-12
    • 2021-02-20
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    相关资源
    最近更新 更多