[kotlin-spring] Revert nested property placeholder in @RequestMapping that Spring cannot resolve #22625
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a regression (#22609) by reverting the nested property placeholder syntax introduced in #22377 back to the simple
${api.base-path:<default>}syntax that worked in version 7.17.0.Before (7.18.0 - broken):
@RequestMapping("${openapi.openAPIPetstore.base-path:${api.base-path:/v2}}")After (this fix - same as 7.17.0):
@RequestMapping("${api.base-path:/v2}")Problem
Spring's
@RequestMappingannotation processing does not properly resolve nested${outer:${inner:default}}property placeholder syntax. While the Kotlin string interpolation of$BASE_PATHworks correctly at compile time (verified viajavap), the nested placeholder structure causes Spring to fail to apply the base path at runtime.This results in API endpoints being mounted at incorrect paths (e.g.,
/gateways/...instead of/api/v1/devices/gateways/...), causing 404 errors when clients call the expected URLs.Setting properties explicitly in
application.propertiesdoes not resolve the issue, confirming that Spring's@RequestMappingannotation processing doesn't support nested placeholder syntax.Solution
Reverted to the simple property placeholder syntax from version 7.17.0:
@RequestMapping("${api.base-path:/v2}")This:
Per-API Base Path Configuration
For users who need different base paths for different APIs (the feature that #22377 attempted to provide), this can be achieved programmatically using Spring's
WebMvcConfigurer:This approach:
Files Changed
Templates
modules/openapi-generator/src/main/resources/kotlin-spring/api.mustachemodules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustachemodules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustachemodules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustachemodules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/application.mustacheTests
modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.javaRelated Issues
Fixes #22609
Testing
testNoRequestMappingAnnotationControllertestNoRequestMappingAnnotationApiInterfacegenerateHttpInterfaceTechnical Committee
cc @dr4ke616 (Kotlin Spring Boot)
Summary by cubic
Reverts Kotlin Spring @RequestMapping from nested property placeholders to the simple ${api.base-path:} so Spring resolves base paths correctly at runtime. Restores 7.17.0 behavior and prevents endpoints mounting at wrong paths.
Written for commit c9ce72a. Summary will update on new commits.