[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.