我使用的是SpringBoot 3.4.1、Java 21.0.5和openapi生成器maven插件7.10.0版。
我想自定义Spring(服务器)生成器模板,为此,我按照官方文档安装了openapi-cli
here
.
因此,为了获取模板,我键入了以下命令:
openapi-generator-cli author template -g spring --library spring-boot -o mytemplates
上面的命令下载模板
mytemplates
文件夹。我有两个问题:
-
在这里面,我只找到了
*.mustache
文件和否
*.class
或
*.java
文件。对吗?
-
我可以在maven构建配置中添加我的自定义选项,并在
.mustache
文件*
*示例
假设这是我的openapi生成器maven插件配置:
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.10.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api-docs.yaml</inputSpec>
<templateResourcePath>${project.basedir}/src/templates/mytemplates</templateResourcePath>
<output>${project.build.directory}/generated-sources</output>
<generatorName>spring</generatorName>
<apiPackage>resources</apiPackage>
<modelPackage>model</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<myCustomProperty>true</myCustomProperty> <!-- my property -->
<configOptions>
<!-- options -->
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
如果我定义一个
<myCustomProperty>
在maven构建配置中(如上所述)并在
*.胡子
文件格式如下:
{{#myCustomProperty}}
.. do some if myProperty is true!
{{/myCustomProperty}}
它会奏效吗?