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
  • #13552
Closed
Open
Issue created Sep 29, 2022 by Administrator@rootContributor

[BUG] Java/Spring: @RequestMapping is unconditionally added to controller with property expression

Created by: uweschaefer

Description

When generating Java/Spring, since 6.1.0 a @RequestMapping annotation is added to every controller type, that contains a property with a supposed default value.

See {{=<% %>=}} @RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}") <%={{ }}=%>

The annotation contains a property expression, that is not resolvable from spring-hateoas, which breaks any hateoas application by creating broken self links like 'http://localhost:8080/${openapi.myProjectName.base-path}/', as the property is not resolved.

In our case

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-09-29T19:10:21.734133+02:00[Europe/Berlin]")
@Validated
@Tag(name = "default", description = "the default API")
@RequestMapping("${openapi.myProject.base-path:}")
public interface DefaultApi {
...

(Also, we assume the > char in >defaultBasePath is a typo?)

OpenAPI declaration file content or url

any API will do as the annotation is added unconditionally

Generation Details

using maven plugin with the following config:

<plugin>
	<groupId>org.openapitools</groupId>
	<artifactId>openapi-generator-maven-plugin</artifactId>
	<version>${open-api-plugin.version}</version>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<inputSpec>${project.basedir}/src/main/resources/open-api.yml</inputSpec>
				<generatorName>spring</generatorName>
				<apiPackage>something.gen.rest</apiPackage>
				<modelPackage>something.gen.model</modelPackage>
				<generateApiDocumentation>false</generateApiDocumentation>
				<generateModelDocumentation>false</generateModelDocumentation>
				<generateApis>true</generateApis>
				<generateModels>true</generateModels>
				<library>spring-boot</library>
				<additionalProperties>
					<!-- currently ignored due to a bug, but should work later -->
					<!-- https://github.com/OpenAPITools/openapi-generator/issues/8192 -->
					<additionalProperty>
						useSpringfox=false
					</additionalProperty>
				</additionalProperties>
				<configOptions>
					<interfaceOnly>true</interfaceOnly>
					<skipDefaultInterface>true</skipDefaultInterface>
					<sourceFolder>src/gen/java/</sourceFolder>
					<hateoas>true</hateoas>
				</configOptions>
			</configuration>
		</execution>
	</executions>
</plugin>
openapi-generator version

6.1.0, 6.2.0

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/13488

Suggest a fix

make it possible to opt out of @RequestMapping annotation generation.

Assignee
Assign to
Time tracking