How can I add my license to the top of files autogenerated by openapi-generator?

huangapple go评论80阅读模式
英文:

How can I add my license to the top of files autogenerated by openapi-generator?

问题

我想自定义openapi-generator,以便在每个文件的顶部自动生成特定许可证头部。

我想我需要编辑openapi-generator/src/main/resources/go/partial_header.mustache,只需在该文件的顶部粘贴一大段许可证文本,这样做好吗?

英文:

I want to customize openapi-generator to auto generate code with a specific license header at the top of every file.

I figured I need to edit openapi-generator/src/main/resources/go/partial_header.mustache, is it a good idea just to paste a bunch of license text on top of that file?

答案1

得分: 2

根据他们的文档,这取决于当前生成器提供的内容,但通常情况下,您需要修改模板,并因此维护一个自定义模板目录。

您在引用的partial_header.mustache模板文件的顶部添加许可内容的唯一限制是,它不应包含jmustache模板引擎可以解释的任何内容。

由于许可文本也不涉及实际代码,因此在模板文件中简单地添加它或甚至替换模板文件中的现有内容应该没有问题。

此外,根据此文档,似乎您可能不需要维护整个模板结构,只需使用生成过程中的外部配置文件部分中所需的模板文件。

英文:

According to their documentation, it depends on what the current generator provides, but in general, you will need to modify the templates and as such, maintain a custom template directory.

The only restriction you would face with adding the license content to the top of the partial_header.mustache template file you referenced, is that it should not contain any content that may be interpretable by the jmustache template engine.

Since the license text also does not involve actual code, there should be no issues with simply adding it to the template file, or even replacing the existing content in the template file.

It also seems as though you may not need to maintain an entire copy of the template structure, and only the template files you need, by using the external configuration files section during generation (According to this documentation).

答案2

得分: 0

这个链接:https://openapi-generator.tech/docs/customization/ 提供了基本信息,但没有涉及具体情况。例如,如果你正在使用openapi maven插件,它没有说明如何进行配置。关键是添加一个configurationFile选项,如下所示:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
    <execution>
        <configuration>
            <templateDirectory>src/main/api-spring-templates</templateDirectory>
            <inputSpec>${basedir}/src/main/api/services/broker-service.yaml</inputSpec>
            <artifactId>broker-api</artifactId>
            <configurationFile>src/main/api-spring-templates/conf.yaml</configurationFile>
            ....
        </configuration>
    </execution>
</executions>

在这个配置文件中,你可以指定任何你需要的额外文件。例如:

files:
   License.mustache:
   templateType: SupportingFiles
   destinationFilename: License.md

当然,你还需要创建相关的License.mustache文件(或者如果不需要模板化,直接创建License.md文件)。这个文件应该在你的模板文件夹中可用,如templateDirectory配置参数所指定的那样。

英文:

This link: https://openapi-generator.tech/docs/customization/ provides the basic information, but it does not address specific cases.
For example, if you are using the openapi maven plugin, it does not specify how you can configure it. The point is to add a configurationFile option, as listed below:

&lt;plugin&gt;
&lt;groupId&gt;org.openapitools&lt;/groupId&gt;
&lt;artifactId&gt;openapi-generator-maven-plugin&lt;/artifactId&gt;
&lt;executions&gt;
    &lt;execution&gt;
        &lt;configuration&gt;
            &lt;templateDirectory&gt;src/main/api-spring-templates&lt;/templateDirectory&gt;
            &lt;inputSpec&gt;${basedir}/src/main/api/services/broker-service.yaml&lt;/inputSpec&gt;
            &lt;artifactId&gt;broker-api&lt;/artifactId&gt;
            &lt;configurationFile&gt;src/main/api-spring-templates/conf.yaml&lt;/configurationFile&gt;
            ....
        &lt;/configuration&gt;
    &lt;/execution&gt;
&lt;/executions&gt;

</plugin>

In this configuration file you can specify any additional files that you would require. For example:

files:
   License.mustache:
   templateType: SupportingFiles
   destinationFilename: License.md

Plus, of course, creating the associated License.mustache file (or directly a License.md file, if no templating is required). This file should be available in your template folder, as specified in the templateDirectory configuration parameter.

huangapple
  • 本文由 发表于 2021年9月3日 00:21:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/69033904.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定