Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: OpenApi Generator Plugin creates unwanted test file

I use OpenApi 3.0 and the maven plugin openapi-generator-maven-plugin to generate my api + objects.

This is my maven config:

                    <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>${project.basedir}/src/main/resources/BookingService.yaml</inputSpec>
                        <generatorName>spring</generatorName>
                        <modelPackage>${clientPackage}.model</modelPackage>
                        <invokerPackage>${clientPackage}.invoker</invokerPackage>
                        <apiPackage>${clientPackage}.api</apiPackage>
                        <generateApis>true</generateApis>
                        <generateApiTests>false</generateApiTests>
                        <generateModelTests>false</generateModelTests>
                        <configOptions>
                            <delegatePattern>true</delegatePattern>
                        </configOptions>
                    </configuration>
                </execution>

It works as expected, however its also generating tests that I do not want. As you can see in my config i disabled the tests for Api tests + Model tests..

enter image description here

The compilation of these tests fail bc it "Cannot resolve symbol 'SpringBootTest'" in the build target folder...

These tests do not have any sense, how can I disable them?

like image 587
M Hot Avatar asked Apr 27 '26 22:04

M Hot


1 Answers

Note this is a workaround. It would be better to get a property to not generate this testcase, but for now this seems to work...

Add this maven plugin to your pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <!-- remove the unwanted generated testcases by the spring generator of openapi -->
                    <delete dir="${project.build.directory}/generated-sources/openapi/src/test" />
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

It will delete that entire test package after the sources have been generated in the process-sources phase

like image 145
Ivonet Avatar answered Apr 30 '26 22:04

Ivonet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!