Make it possible to disable generation of swagger annotations
Created by: barfoo4711
We are using openapi-generator-maven-plugin to generate Java classes from swagger files. We are not using swagger but Spring rest template + jackson for triggering REST services.
Code generation works great but unfortunately openapi-generator-maven-plugin always includes swagger annotations in the code. In order for being able to compile the code we have to use the com.google.code.maven-replacer-plugin:replacer maven plugin to get rid of the annoations - otherwise the code does not compile since we don't have any swagger dependencies included (and also can't add them for technical reasons).
Would be great if there would be an option to disable the generation of the annotations since we don't need them.
This is the plugin config we are using
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.1</version>
<executions>
<execution>
<id>security</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/yaml/xxx.json</inputSpec>
<output>${project.build.directory}/generated-sources/openapi/xxx/src</output>
<modelPackage>xxx</modelPackage>
<generatorName>java</generatorName>
<library>resttemplate</library>
<addCompileSourceRoot>true</addCompileSourceRoot>
<generateApis>false</generateApis>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<serializableModel>true</serializableModel>
<dateLibrary>legacy</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
This is the workaround we are using
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>removeUnusedAnnotationImports</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${project.basedir}</basedir>
<includes>
<include>target/generated-sources/openapi/**/*.java</include>
</includes>
<regex>false</regex>
<replacements>
<replacement>
<token>import io.swagger.annotations.ApiModel;</token>
<value />
</replacement>
<replacement>
<token>import io.swagger.annotations.ApiModelProperty;</token>
<value />
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>removeUnusedAnnotations</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${project.basedir}</basedir>
<includes>
<include>target/generated-sources/openapi/**/*.java</include>
</includes>
<replacements>
<replacement>
<token>@ApiModel.*\)</token>
<value />
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>