Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8719
Closed
Open
Issue created Feb 16, 2021 by Administrator@rootContributor

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>				
Assignee
Assign to
Time tracking