diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache
index f868eaa6dbf3..aa27beb2d01b 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache
@@ -8,6 +8,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
+{{! RootUriTemplateHandler }}
+import org.springframework.boot.web.client.RootUriTemplateHandler;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
@@ -704,8 +706,16 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
//Append to finalUri the templatized query string like "?param1={param1Value}&.......
finalUri += "?" + queryUri;
}
+
String expandedPath = this.expandPath(finalUri, uriParams);
- final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(expandedPath);
+
+ final UriComponentsBuilder builder;
+ {{! RootUriTemplateHandler }}
+ if (restTemplate.getUriTemplateHandler() instanceof RootUriTemplateHandler) {
+ builder = UriComponentsBuilder.fromPath(expandedPath);
+ } else {
+ builder = UriComponentsBuilder.fromHttpUrl(basePath).path(expandedPath);
+ }
URI uri;
try {
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pom.mustache
index 6bd56372de2e..26eebeab5134 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pom.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pom.mustache
@@ -230,6 +230,14 @@
spring-web
${spring-web-version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ 2.6.2
+
+
org.springframework
spring-context