javaspring-bootmustacheopenapi-generator-maven-pluginopenapi-generator-cli

springdoc-openapi-generator template customization


I'm using SpringBoot 3.4.1, Java 21.0.5 and openapi-generator-maven-plugin ver 7.10.0. I want to customize the Spring (server) generator template and, to do that, I installing the openapi-cli following the official docs here.

Therefore to grab the template I have typed the follow command:

openapi-generator-cli author template -g spring --library spring-boot -o mytemplates

the above command download the template under mytemplates folder. I have two questions:

  1. Inside this I found only *.mustache file and no *.class or *.java file. Is it correct?
  2. Can I add my custom option inside maven build configuration and referencing it inside a .mustache file? *¹

*¹ Example

Suppose this is my openapi-generator-maven-plugin configuration:

<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>

If I define a <myCustomProperty> inside maven build config (as above) and reference it in a *.mustache file this way:

{{#myCustomProperty}}
  .. do some if myProperty is true!
{{/myCustomProperty}}

will it work?


Solution

  • Yes, it will. Your custom properties get passed to the mustache template so you can reference it there too.

    Sorry about the short answer I gotta go somewhere but I'll try to remember to fill it out a bit if you want & nobody else has by then.