diff --git a/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml b/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml index ce0d79f6e97b..dc46abecec9d 100644 --- a/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml +++ b/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml @@ -13,3 +13,4 @@ additionalProperties: reactive: false useResponseEntity: true useFlowForArrayReturnType: false + requestMappingMode: "api_interface" diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache index 4a384caa2a9c..603093a7f176 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache @@ -6,6 +6,9 @@ package {{package}} {{#imports}}import {{import}} {{/imports}} +{{#useRequestMappingOnInterface}} +import {{#apiPackage}}{{.}}.{{/apiPackage}}{{classname}}.Companion.BASE_PATH +{{/useRequestMappingOnInterface}} {{#swagger2AnnotationLibrary}} import io.swagger.v3.oas.annotations.* @@ -48,7 +51,7 @@ import kotlin.collections.List import kotlin.collections.Map {{#useRequestMappingOnInterface}} -@HttpExchange("\${api.base-path:{{contextPath}}}") +@HttpExchange(BASE_PATH) // Generate with 'requestMappingMode' set to 'none' to skip the base path on the interface {{/useRequestMappingOnInterface}} {{#useBeanValidation}} @Validated @@ -74,9 +77,7 @@ interface {{classname}} { {{/operation}} companion object { //for your own safety never directly reuse these path definitions in tests - {{#useRequestMappingOnInterface}} const val BASE_PATH: String = "{{=<% %>=}}<%contextPath%><%={{ }}=%>" - {{/useRequestMappingOnInterface}} {{#operation}} const val PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}: String = "{{{path}}}" {{/operation}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java index e8101f0d53b5..ded1970b374a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java @@ -1097,6 +1097,7 @@ public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exce + " ): Mono>", " companion object {\n" + " //for your own safety never directly reuse these path definitions in tests\n" + + " const val BASE_PATH: String = \"/v2\"\n" + " const val PATH_DELETE_ORDER: String = \"/store/order/{orderId}\"\n" + " const val PATH_GET_INVENTORY: String = \"/store/inventory\"\n" + " const val PATH_GET_ORDER_BY_ID: String = \"/store/order/{orderId}\"\n" @@ -1105,7 +1106,8 @@ public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exce ); assertFileNotContains( path, - "suspend" + "suspend", + "@HttpExchange(BASE_PATH)" // this should not be present since "requestMappingMode" is set to "none" ); } @@ -1314,11 +1316,11 @@ public void generateHttpInterface() throws Exception { generator.opts(input).generate(); Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/StoreApiClient.kt"); - // Note: We use simple ${api.base-path:} syntax because Spring's @HttpExchange - // doesn't properly resolve nested ${outer:${inner:default}} property placeholder syntax + // Note: We cannot use property placeholders as HttpServiceProxyFactory does not resolve them by default. assertFileContains( path, - "@HttpExchange(\"\\${api.base-path:/v2}\")", + "import org.openapitools.api.StoreApi.Companion.BASE_PATH", + "@HttpExchange(BASE_PATH) // Generate with 'requestMappingMode' set to 'none' to skip the base path on the interface", // this should be present since "requestMappingMode" is set to "api_interface" " fun getInventory(\n" + " ): Map", " fun deleteOrder(\n" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt index 7b2af7510d63..1f33511dd15d 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -109,6 +109,7 @@ interface PetApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_ADD_PET: String = "/pet" const val PATH_DELETE_PET: String = "/pet/{petId}" const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 7c94a2c09a0a..f3691f3d439b 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -65,6 +65,7 @@ interface StoreApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" const val PATH_GET_INVENTORY: String = "/store/inventory" const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt index 67ecef197e65..2ebfd2a7ab5d 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -102,6 +102,7 @@ interface UserApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_CREATE_USER: String = "/user" const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt index fbc8a9bdb11a..3c4d9142e339 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -109,6 +109,7 @@ interface PetApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_ADD_PET: String = "/pet" const val PATH_DELETE_PET: String = "/pet/{petId}" const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 0eb0d1faf240..758b77478b53 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -66,6 +66,7 @@ interface StoreApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" const val PATH_GET_INVENTORY: String = "/store/inventory" const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt index 15ccf0e0589f..f9eeffea6184 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -104,6 +104,7 @@ interface UserApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_CREATE_USER: String = "/user" const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt index c435585c469e..aab634d52ca8 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -6,6 +6,7 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet +import org.openapitools.api.PetApi.Companion.BASE_PATH import io.swagger.v3.oas.annotations.* import io.swagger.v3.oas.annotations.enums.* @@ -25,6 +26,7 @@ import jakarta.validation.constraints.* import kotlin.collections.List import kotlin.collections.Map +@HttpExchange(BASE_PATH) // Generate with 'requestMappingMode' set to 'none' to skip the base path on the interface @Validated interface PetApi { @@ -107,6 +109,7 @@ interface PetApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_ADD_PET: String = "/pet" const val PATH_DELETE_PET: String = "/pet/{petId}" const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 5ae8679640d8..1069b16f057b 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -5,6 +5,7 @@ package org.openapitools.api import org.openapitools.model.Order +import org.openapitools.api.StoreApi.Companion.BASE_PATH import io.swagger.v3.oas.annotations.* import io.swagger.v3.oas.annotations.enums.* @@ -24,6 +25,7 @@ import jakarta.validation.constraints.* import kotlin.collections.List import kotlin.collections.Map +@HttpExchange(BASE_PATH) // Generate with 'requestMappingMode' set to 'none' to skip the base path on the interface @Validated interface StoreApi { @@ -64,6 +66,7 @@ interface StoreApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" const val PATH_GET_INVENTORY: String = "/store/inventory" const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt index 019895e02376..e9e9bb1f5449 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -5,6 +5,7 @@ package org.openapitools.api import org.openapitools.model.User +import org.openapitools.api.UserApi.Companion.BASE_PATH import io.swagger.v3.oas.annotations.* import io.swagger.v3.oas.annotations.enums.* @@ -24,6 +25,7 @@ import jakarta.validation.constraints.* import kotlin.collections.List import kotlin.collections.Map +@HttpExchange(BASE_PATH) // Generate with 'requestMappingMode' set to 'none' to skip the base path on the interface @Validated interface UserApi { @@ -102,6 +104,7 @@ interface UserApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_CREATE_USER: String = "/user" const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt index c435585c469e..c5c2231999fb 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -107,6 +107,7 @@ interface PetApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_ADD_PET: String = "/pet" const val PATH_DELETE_PET: String = "/pet/{petId}" const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 5ae8679640d8..238669dd8272 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -64,6 +64,7 @@ interface StoreApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" const val PATH_GET_INVENTORY: String = "/store/inventory" const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt index 019895e02376..069f93bb1fa1 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -102,6 +102,7 @@ interface UserApi { companion object { //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" const val PATH_CREATE_USER: String = "/user" const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList"