Make it possible to disable generation of swagger annotations
See original GitHub issueWe 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>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:17
- Comments:8 (2 by maintainers)
Top GitHub Comments
I’m creating a project with generator “spring”. There I’m also getting the Swagger Annotations. Can’t find a way to disable it.
When working with “kotlin-spring” there was this option, but can’t find it for “spring” (create java spring project). https://openapi-generator.tech/docs/generators/kotlin-spring/
But it seems that “spring” generator doesn’t have this option. https://openapi-generator.tech/docs/generators/spring/
I’m getting errors on for example, the following imports:
Humphrey
+1