Skip to content

Commit a2c2426

Browse files
committed
fix fallback to nested placeholders.
1 parent a211f1d commit a2c2426

58 files changed

Lines changed: 115 additions & 62 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import kotlin.collections.Map
6161
{{/swagger1AnnotationLibrary}}
6262
{{#useRequestMappingOnController}}
6363
{{=<% %>=}}
64-
@RequestMapping("\${api.<%title%>.base-path:api.base-path:$BASE_PATH}")
64+
@RequestMapping("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
6565
<%={{ }}=%>
6666
{{/useRequestMappingOnController}}
6767
{{#operations}}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package {{package}}
33
import org.springframework.stereotype.Controller
44
import org.springframework.web.bind.annotation.RequestMapping
55
import java.util.Optional
6+
{{#useRequestMappingOnController}}
7+
import {{#apiPackage}}{{.}}.{{/apiPackage}}{{classname}}Controller.Companion.BASE_PATH
8+
{{/useRequestMappingOnController}}
69

710
{{>generatedAnnotation}}
811

912
@Controller{{#beanQualifiers}}("{{package}}.{{classname}}Controller"){{/beanQualifiers}}
1013
{{#useRequestMappingOnController}}
1114
{{=<% %>=}}
12-
@RequestMapping("\${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
15+
@RequestMapping("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
1316
<%={{ }}=%>
1417
{{/useRequestMappingOnController}}
1518
{{#operations}}
@@ -30,5 +33,13 @@ class {{classname}}Controller(
3033
{{/skipDefaultDelegateInterface}}
3134

3235
override fun getDelegate(): {{classname}}Delegate = delegate
36+
{{#useRequestMappingOnController}}
37+
38+
companion object {
39+
//for your own safety never directly reuse these path definitions in tests
40+
const val BASE_PATH: String = "{{=<% %>=}}<%>defaultBasePath%><%={{ }}=%>"
41+
}
42+
43+
{{/useRequestMappingOnController}}
3344
}
3445
{{/operations}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import kotlin.collections.Map
6868
{{/swagger1AnnotationLibrary}}
6969
{{#useRequestMappingOnInterface}}
7070
{{=<% %>=}}
71-
@RequestMapping("\${api.<%title%>.base-path:api.base-path:$BASE_PATH}")
71+
@RequestMapping("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
7272
<%={{ }}=%>
7373
{{/useRequestMappingOnInterface}}
7474
{{#operations}}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ import reactor.core.publisher.Mono
5050
import kotlin.collections.List
5151
import kotlin.collections.Map
5252

53-
{{#useRequestMappingOnInterface}}@HttpExchange(
54-
"{{=<% %>=}}\${api.<%title%>.base-path:api.base-path:$BASE_PATH}<%={{ }}=%>"
55-
){{/useRequestMappingOnInterface}}
53+
{{#useRequestMappingOnInterface}}
54+
{{=<% %>=}}
55+
@HttpExchange("\${openapi.<%title%>.base-path:\${api.base-path:$BASE_PATH}}")
56+
<%={{ }}=%>
57+
{{/useRequestMappingOnInterface}}
5658
{{#useBeanValidation}}
5759
@Validated
5860
{{/useBeanValidation}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SpringFoxConfiguration {
3636

3737
@Bean
3838
{{=<% %>=}}
39-
fun customImplementation(servletContext: ServletContext, @Value("\${openapi.<%title%>.base-path:<%>defaultBasePath%>}") basePath: String): Docket {
39+
fun customImplementation(servletContext: ServletContext, @Value("\${openapi.<%title%>.base-path:\${api.base-path:<%>defaultBasePath%>}}") basePath: String): Docket {
4040
<%={{ }}=%>
4141
return Docket(DocumentationType.SWAGGER_2)
4242
.select()

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ public void testNoRequestMappingAnnotationController() throws IOException {
143143
// Check that the @RequestMapping annotation is generated in the ApiController file
144144
assertFileContains(
145145
Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApiController.kt"),
146-
"@RequestMapping(\"\\${"
146+
"@RequestMapping(\"\\${openapi.openAPIPetstore.base-path:\\${api.base-path:$BASE_PATH}}\")",
147+
" companion object {\n"
148+
+ " //for your own safety never directly reuse these path definitions in tests\n"
149+
+ " const val BASE_PATH: String = \"/v2\"\n"
150+
+ " }"
147151
);
148152
}
149153

@@ -154,7 +158,10 @@ public void testNoRequestMappingAnnotationApiInterface() throws IOException {
154158
// Check that the @RequestMapping annotation is generated in the Api file
155159
assertFileContains(
156160
Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApi.kt"),
157-
"@RequestMapping(\"\\${"
161+
"@RequestMapping(\"\\${openapi.openAPIPetstore.base-path:\\${api.base-path:$BASE_PATH}}\")",
162+
" companion object {\n"
163+
+ " //for your own safety never directly reuse these path definitions in tests\n"
164+
+ " const val BASE_PATH: String = \"/v2\""
158165
);
159166
// Check that the @RequestMapping annotation is not generated in the ApiController file
160167
assertFileNotContains(
@@ -1286,7 +1293,7 @@ public void generateHttpInterface() throws Exception {
12861293
codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface");
12871294
codegen.additionalProperties().put(REACTIVE, false);
12881295
codegen.additionalProperties().put(USE_RESPONSE_ENTITY, false);
1289-
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none");
1296+
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "api_interface");
12901297
codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false);
12911298

12921299
ClientOptInput input = new ClientOptInput()
@@ -1305,6 +1312,9 @@ public void generateHttpInterface() throws Exception {
13051312
Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/StoreApiClient.kt");
13061313
assertFileContains(
13071314
path,
1315+
"@HttpExchange(\n"
1316+
+ "\"\\${openapi.openAPIPetstore.base-path:\\${api.base-path:$BASE_PATH}}\"\n"
1317+
+ ")",
13081318
" fun getInventory(\n"
13091319
+ " ): Map<String, kotlin.Int>",
13101320
" fun deleteOrder(\n"

samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import jakarta.validation.constraints.*
2525
import kotlin.collections.List
2626
import kotlin.collections.Map
2727

28-
2928
@Validated
3029
interface PetApi {
3130

samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import jakarta.validation.constraints.*
2424
import kotlin.collections.List
2525
import kotlin.collections.Map
2626

27-
2827
@Validated
2928
interface StoreApi {
3029

samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import jakarta.validation.constraints.*
2424
import kotlin.collections.List
2525
import kotlin.collections.Map
2626

27-
2827
@Validated
2928
interface UserApi {
3029

samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import reactor.core.publisher.Mono
2727
import kotlin.collections.List
2828
import kotlin.collections.Map
2929

30-
3130
@Validated
3231
interface PetApi {
3332

0 commit comments

Comments
 (0)