Skip to content

Commit c772270

Browse files
[kotlin-spring] Revert nested property placeholder in @RequestMapping that Spring cannot resolve
1 parent 570915e commit c772270

44 files changed

Lines changed: 52 additions & 56 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ import kotlin.collections.Map
6060
@Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API")
6161
{{/swagger1AnnotationLibrary}}
6262
{{#useRequestMappingOnController}}
63-
{{=<% %>=}}
64-
@RequestMapping("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
65-
<%={{ }}=%>
63+
@RequestMapping("\${api.base-path:{{contextPath}}}")
6664
{{/useRequestMappingOnController}}
6765
{{#operations}}
6866
class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) val service: {{classname}}Service{{/serviceInterface}}) {

modules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import {{#apiPackage}}{{.}}.{{/apiPackage}}{{classname}}Controller.Companion.BAS
1111

1212
@Controller{{#beanQualifiers}}("{{package}}.{{classname}}Controller"){{/beanQualifiers}}
1313
{{#useRequestMappingOnController}}
14-
{{=<% %>=}}
15-
@RequestMapping("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
16-
<%={{ }}=%>
14+
@RequestMapping("\${api.base-path:{{contextPath}}}")
1715
{{/useRequestMappingOnController}}
1816
{{#operations}}
1917
class {{classname}}Controller(

modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ import kotlin.collections.Map
6767
@Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API")
6868
{{/swagger1AnnotationLibrary}}
6969
{{#useRequestMappingOnInterface}}
70-
{{=<% %>=}}
71-
@RequestMapping("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
72-
<%={{ }}=%>
70+
@RequestMapping("\${api.base-path:{{contextPath}}}")
7371
{{/useRequestMappingOnInterface}}
7472
{{#operations}}
7573
interface {{classname}} {

modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ import kotlin.collections.List
5151
import kotlin.collections.Map
5252

5353
{{#useRequestMappingOnInterface}}
54-
{{=<% %>=}}
55-
@HttpExchange("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
56-
<%={{ }}=%>
54+
@HttpExchange("\${api.base-path:{{contextPath}}}")
5755
{{/useRequestMappingOnInterface}}
5856
{{#useBeanValidation}}
5957
@Validated

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ public void testNoRequestMappingAnnotationController() throws IOException {
141141
"@RequestMapping(\"\\${"
142142
);
143143
// Check that the @RequestMapping annotation is generated in the ApiController file
144+
// Note: We use simple ${api.base-path:<default>} syntax because Spring's @RequestMapping
145+
// doesn't properly resolve nested ${outer:${inner:default}} property placeholder syntax
144146
assertFileContains(
145147
Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApiController.kt"),
146-
"@RequestMapping(\"\\${openapi.openAPIPetstore.base-path:\\${api.base-path:$BASE_PATH}}\")",
148+
"@RequestMapping(\"\\${api.base-path:/v2}\")",
147149
" companion object {\n"
148150
+ " //for your own safety never directly reuse these path definitions in tests\n"
149151
+ " const val BASE_PATH: String = \"/v2\"\n"
@@ -156,9 +158,11 @@ public void testNoRequestMappingAnnotationApiInterface() throws IOException {
156158
File output = generatePetstoreWithRequestMappingMode(KotlinSpringServerCodegen.RequestMappingMode.api_interface);
157159

158160
// Check that the @RequestMapping annotation is generated in the Api file
161+
// Note: We use simple ${api.base-path:<default>} syntax because Spring's @RequestMapping
162+
// doesn't properly resolve nested ${outer:${inner:default}} property placeholder syntax
159163
assertFileContains(
160164
Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApi.kt"),
161-
"@RequestMapping(\"\\${openapi.openAPIPetstore.base-path:\\${api.base-path:$BASE_PATH}}\")",
165+
"@RequestMapping(\"\\${api.base-path:/v2}\")",
162166
" companion object {\n"
163167
+ " //for your own safety never directly reuse these path definitions in tests\n"
164168
+ " const val BASE_PATH: String = \"/v2\""
@@ -1310,11 +1314,11 @@ public void generateHttpInterface() throws Exception {
13101314
generator.opts(input).generate();
13111315

13121316
Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/StoreApiClient.kt");
1317+
// Note: We use simple ${api.base-path:<default>} syntax because Spring's @HttpExchange
1318+
// doesn't properly resolve nested ${outer:${inner:default}} property placeholder syntax
13131319
assertFileContains(
13141320
path,
1315-
"@HttpExchange(\n"
1316-
+ "\"\\${openapi.openAPIPetstore.base-path:\\${api.base-path:$BASE_PATH}}\"\n"
1317-
+ ")",
1321+
"@HttpExchange(\"\\${api.base-path:/v2}\")",
13181322
" fun getInventory(\n"
13191323
+ " ): Map<String, kotlin.Int>",
13201324
" fun deleteOrder(\n"

samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/FakeApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import kotlin.collections.Map
3131

3232
@RestController
3333
@Validated
34-
@RequestMapping("\${openapi.openAPIPetstore.base-path:\${api.base-path:$BASE_PATH}}")
34+
@RequestMapping("\${api.base-path:/v2}")
3535
class FakeApiController() {
3636

3737
@Operation(

samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/PetApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import kotlin.collections.Map
3232

3333
@RestController
3434
@Validated
35-
@RequestMapping("\${openapi.openAPIPetstore.base-path:\${api.base-path:$BASE_PATH}}")
35+
@RequestMapping("\${api.base-path:/v2}")
3636
class PetApiController() {
3737

3838
@Operation(

samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/StoreApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import kotlin.collections.Map
3131

3232
@RestController
3333
@Validated
34-
@RequestMapping("\${openapi.openAPIPetstore.base-path:\${api.base-path:$BASE_PATH}}")
34+
@RequestMapping("\${api.base-path:/v2}")
3535
class StoreApiController() {
3636

3737
@Operation(

samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/UserApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import kotlin.collections.Map
3131

3232
@RestController
3333
@Validated
34-
@RequestMapping("\${openapi.openAPIPetstore.base-path:\${api.base-path:$BASE_PATH}}")
34+
@RequestMapping("\${api.base-path:/v2}")
3535
class UserApiController() {
3636

3737
@Operation(

samples/server/petstore/kotlin-springboot-bigdecimal-default/src/main/kotlin/org/openapitools/api/TestApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import kotlin.collections.Map
3131

3232
@RestController
3333
@Validated
34-
@RequestMapping("\${openapi.demo.base-path:\${api.base-path:$BASE_PATH}}")
34+
@RequestMapping("\${api.base-path:}")
3535
class TestApiController() {
3636

3737
@Operation(

0 commit comments

Comments
 (0)