question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it possible to disable generation of swagger annotations

See original GitHub issue

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>				

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:17
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

27reactions
hmmlopezcommented, Mar 24, 2021

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/

swaggerAnnotations generate swagger annotations to go alongside controllers and models false

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:

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

Humphrey

0reactions
bhuismcommented, Sep 26, 2022

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Turn Off Swagger-ui in Production - Baeldung
In this article, we looked at solutions for disabling Swagger in production. We looked at how to toggle the bean that turns Swagger...
Read more >
How to disable swagger-ui in custom environments at runtime
I have a custom annotation defined below which exists in a shared common library that all microservices in the project will use.
Read more >
Swagger Codegen Documentation
The Swagger Codegen is an open source code-generator to build server stubs and client SDKs directly from a Swagger defined RESTful API. The...
Read more >
Using OpenAPI and Swagger UI - Quarkus
Hit CTRL+C to stop the application. Providing Application Level OpenAPI Annotations. There are some MicroProfile OpenAPI annotations which describe global API ...
Read more >
Documentation for the spring Generator
Select the complementary documentation annotation library. none: Do not annotate Model and Api with complementary annotations. swagger1 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found