swagger-codegen-maven-plugin ignore the generateApiTests=false option
after mvn install test package present in generated sources and contains tests for api
plugin section in pom
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api/api.yaml</inputSpec>
<language>java</language>
<library>resttemplate</library>
<output>${project.build.directory}/generated-sources/openapi</output>
<apiPackage>org.openapitools.api</apiPackage>
<modelPackage>org.openapitools.model</modelPackage>
<invokerPackage>org.openapitools.invoker</invokerPackage>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<configOptions>
<dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
3.0.0
We are also suffering from this bug. It generates spring boot 2 tests but we are still using spring boot 1.X.
Our quick fix was to delete the generated test classes via the Maven plugin maven-clean-plugin right after the tests have been created. It is working but not very satisfying.
I took a closer look into this problem.
The CodeGenMojo set some system properties:
...
System.setProperty(CodegenConstants.API_TESTS, generateApiTests.toString());
...
but the DefaultGenerator does not consider these system properties
...
getCustomOptionBooleanValue(CodegenConstants.API_TESTS_OPTION);
...
This are probably the cli option, if they are not set default values will be used.
...
generateApiTests = generateAPITestsOption != null ? generateAPITestsOption : getGeneratorPropertyDefaultSwitch(CodegenConstants.API_TESTS, true);
I also have the assumption that the other properties defined in the pom.xml
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
are also ignored. Can you verify this @coolaider ?
I can create a PR regarding the generation of API tests probably by next week.
This is quite annoying, one has to fall back to .swagger-codegen-ignore to skip test generation.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>${ant-contrib.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<available file="${swagger-output-folder}" type="dir" property="patchSwaggerCodegen8781"/>
<if>
<equals arg1="${patchSwaggerCodegen8781}" arg2="true" />
<then>
<echo message="Patching ${swagger-output-folder}/.swagger-codegen-ignore!" level="info" />
<echo message=" Remove once below bug has been fixed:" level="info" />
<echo message=" https://github.com/swagger-api/swagger-codegen/issues/8781" level="info" />
<echo file="${swagger-output-folder}/.swagger-codegen-ignore" append="true">
**Test.java
</echo>
</then>
</if>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
And the code is generated under generated-sources and not generated-test-sources, so compiling does not work for swagger2 either. At least I haven't figured out a way
It would be great if this fix would be back-ported to 2.4.x as it causing us issues.
Most helpful comment
And the code is generated under generated-sources and not generated-test-sources, so compiling does not work for swagger2 either. At least I haven't figured out a way