简体   繁体   English

OpenApi - CodeGeneration - 避免/修改标题注释中的版本生成

[英]OpenApi - CodeGeneration - Avoid/Modify Generation Of Version In Header Comments

We are generating java clients/models by the gradle plugin: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc我们正在通过 gradle 插件生成 java 客户端/模型: https ://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc

Generation works fine, and the header of the generated files locks like this, just an example:生成工作正常,生成文件的标题像这样锁定,只是一个例子:

在此处输入图像描述

Is there a way to change the version-string for the generation to a fix value without changing the whole gradle-version?有没有办法在不更改整个 gradle-version 的情况下将生成的版本字符串更改为固定值? Or even customize the generation of the file-header-comments somehow?甚至以某种方式自定义文件头注释的生成?

This would be very helpful to avoid too much commit-changes in the generated models each time, for files that are not affected by the current modifications.对于不受当前修改影响的文件,这对于避免每次在生成的模型中进行过多的提交更改非常有帮助。

/**
 * Client classes generation (java)
 */
task generateApiCodeJavaClient(type: ext.GenerateTask) {
    group = "openapi tools"
    dependsOn "generateOpenApiDocs"

    generatorName = "java"

    inputSpec = openApiYamlPath
    outputDir = project.ext.javaCodeDir

    inputs.file inputSpec
    outputs.dir outputDir
   
    configOptions = [
            dateLibrary: "java8",
            java8: "true",
            hideGenerationTimestamp: "true",
            library: "resttemplate"
    ]
}

Any suggestions?有什么建议么? Thanx.谢谢。

Ok, it has nothing directly to do with the openapi-generator-gradle-plugin, rather than with schema definition.好的,它与 openapi-generator-gradle-plugin 没有直接关系,与模式定义无关。 Modifying the version in io.swagger.v3.oas.annotations.info-Annotation fixed this issue.修改 io.swagger.v3.oas.annotations.info-Annotation 中的版本修复了这个问题。

在此处输入图像描述

There is also another way to modify the version text for the Swagger-Application-Start, but this did not work for me, maybe parameters are not 100% correct.还有另一种方法可以修改 Swagger-Application-Start 的版本文本,但这对我不起作用,可能参数不是 100% 正确。 See commented-out line with 'forkProperties'.请参阅带有“forkProperties”的注释行。 If someone knows anything about this comments are welcome.如果有人对此评论有所了解,欢迎提出。

openApi {
    // http://localhost:58427/openapi/api-docs.yaml
    apiDocsUrl.set("http://localhost:$openApiPort/openapi/api-docs.yaml")
    outputDir.set(file("$openApiYamlLocation"))
    outputFileName.set("$openApiYamlFileName")
    //forkProperties = "-Dspring-boot.run.arguments='--spring.application.version=$productWinVersion'"
    waitTimeInSeconds.set(120)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM