From c7121d048cfa6691dc3b0a675ddc790d5f7dc713 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 17 Sep 2025 11:48:49 +0100 Subject: [PATCH] Replace X-API-Version with API-Version Closes gh-35494 --- framework-docs/modules/ROOT/pages/web/webflux/config.adoc | 4 ++-- .../mvcconfig/mvcconfigapiversion/WebConfiguration.java | 2 +- .../mvcconfig/mvcconfigapiversion/WebConfiguration.kt | 2 +- .../test/web/reactive/server/samples/ApiVersionTests.java | 4 ++-- .../test/web/servlet/client/samples/ApiVersionTests.java | 4 ++-- .../web/client/RestClientVersionTests.java | 8 ++++---- .../web/client/support/RestClientAdapterTests.java | 4 ++-- .../reactive/function/client/WebClientVersionTests.java | 8 ++++---- .../server/support/RouterFunctionMappingVersionTests.java | 6 +++--- .../annotation/RequestMappingVersionIntegrationTests.java | 4 ++-- .../WebMvcConfigurationSupportExtensionTests.java | 2 +- .../support/RouterFunctionMappingVersionTests.java | 6 +++--- .../RequestMappingVersionHandlerMethodTests.java | 4 ++-- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/web/webflux/config.adoc b/framework-docs/modules/ROOT/pages/web/webflux/config.adoc index 65259c6c18f..9f3e371686f 100644 --- a/framework-docs/modules/ROOT/pages/web/webflux/config.adoc +++ b/framework-docs/modules/ROOT/pages/web/webflux/config.adoc @@ -691,7 +691,7 @@ Java:: @Override public void configureApiVersioning(ApiVersionConfigurer configurer) { - configurer.useRequestHeader("X-API-Version"); + configurer.useRequestHeader("API-Version"); } } ---- @@ -704,7 +704,7 @@ Kotlin:: class WebConfiguration : WebMvcConfigurer { override fun configureApiVersioning(configurer: ApiVersionConfigurer) { - configurer.useRequestHeader("X-API-Version") + configurer.useRequestHeader("API-Version") } } ---- diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.java index a58293146da..e99f555c14e 100644 --- a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.java @@ -26,7 +26,7 @@ public class WebConfiguration implements WebMvcConfigurer { @Override public void configureApiVersioning(ApiVersionConfigurer configurer) { - configurer.useRequestHeader("X-API-Version"); } + configurer.useRequestHeader("API-Version"); } // end::snippet[] diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.kt index dec34ad9196..4a315aef00b 100644 --- a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.kt +++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.kt @@ -25,7 +25,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer class WebConfiguration : WebMvcConfigurer { override fun configureApiVersioning(configurer: ApiVersionConfigurer) { - configurer.useRequestHeader("X-API-Version") + configurer.useRequestHeader("API-Version") } } // end::snippet[] \ No newline at end of file diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ApiVersionTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ApiVersionTests.java index 6efcc987caf..457db241c65 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ApiVersionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ApiVersionTests.java @@ -40,7 +40,7 @@ public class ApiVersionTests { @Test void header() { - String header = "X-API-Version"; + String header = "API-Version"; Map result = performRequest( configurer -> configurer.useRequestHeader(header), @@ -92,7 +92,7 @@ public class ApiVersionTests { @RestController static class TestController { - private static final String HEADER = "X-API-Version"; + private static final String HEADER = "API-Version"; @GetMapping(path = "/**", version = "1.2") Map handle(ServerHttpRequest request) { diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/client/samples/ApiVersionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/client/samples/ApiVersionTests.java index 70af17d22e0..a9b8d0a4ff5 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/client/samples/ApiVersionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/client/samples/ApiVersionTests.java @@ -44,7 +44,7 @@ public class ApiVersionTests { @Test void header() { - String header = "X-API-Version"; + String header = "API-Version"; Map result = performRequest( request -> request.getHeader(header), ApiVersionInserter.useHeader(header)); @@ -96,7 +96,7 @@ public class ApiVersionTests { @RestController private static class TestController { - private static final String HEADER = "X-API-Version"; + private static final String HEADER = "API-Version"; @GetMapping(path = "/**", version = "1.2") Map handle(HttpServletRequest request) { diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientVersionTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientVersionTests.java index 7ea43c0ab95..c570c183407 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientVersionTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientVersionTests.java @@ -64,8 +64,8 @@ public class RestClientVersionTests { @Test void header() { - performRequest(ApiVersionInserter.useHeader("X-API-Version")); - expectRequest(request -> assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2")); + performRequest(ApiVersionInserter.useHeader("API-Version")); + expectRequest(request -> assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2")); } @Test @@ -101,11 +101,11 @@ public class RestClientVersionTests { @Test void defaultVersion() { - ApiVersionInserter inserter = ApiVersionInserter.useHeader("X-API-Version"); + ApiVersionInserter inserter = ApiVersionInserter.useHeader("API-Version"); RestClient restClient = restClientBuilder.defaultApiVersion(1.2).apiVersionInserter(inserter).build(); restClient.get().uri("/path").retrieve().body(String.class); - expectRequest(request -> assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2")); + expectRequest(request -> assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2")); } private void performRequest(ApiVersionInserter versionInserter) { diff --git a/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java b/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java index 648accfd3f9..2a7ec592145 100644 --- a/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java @@ -187,7 +187,7 @@ class RestClientAdapterTests { RestClient restClient = RestClient.builder() .baseUrl(anotherServer.url("/").toString()) - .apiVersionInserter(ApiVersionInserter.useHeader("X-API-Version")) + .apiVersionInserter(ApiVersionInserter.useHeader("API-Version")) .build(); RestClientAdapter adapter = RestClientAdapter.create(restClient); @@ -196,7 +196,7 @@ class RestClientAdapterTests { String actualResponse = service.getGreetingWithVersion(); RecordedRequest request = anotherServer.takeRequest(); - assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2"); + assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2"); assertThat(actualResponse).isEqualTo("Hello Spring 2!"); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientVersionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientVersionTests.java index 0daabd73cbf..23d55259907 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientVersionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientVersionTests.java @@ -61,8 +61,8 @@ public class WebClientVersionTests { @Test void header() { - performRequest(ApiVersionInserter.useHeader("X-API-Version")); - expectRequest(request -> assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2")); + performRequest(ApiVersionInserter.useHeader("API-Version")); + expectRequest(request -> assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2")); } @Test @@ -92,11 +92,11 @@ public class WebClientVersionTests { @Test void defaultVersion() { - ApiVersionInserter inserter = ApiVersionInserter.useHeader("X-API-Version"); + ApiVersionInserter inserter = ApiVersionInserter.useHeader("API-Version"); WebClient webClient = webClientBuilder.defaultApiVersion(1.2).apiVersionInserter(inserter).build(); webClient.get().uri("/path").retrieve().bodyToMono(String.class).block(); - expectRequest(request -> assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2")); + expectRequest(request -> assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2")); } private void performRequest(ApiVersionInserter versionInserter) { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingVersionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingVersionTests.java index 65bd85ad1dd..1a07389da41 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingVersionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingVersionTests.java @@ -70,7 +70,7 @@ public class RouterFunctionMappingVersionTests { private void testGetHandler(String version, String expectedBody) { MockServerWebExchange exchange = MockServerWebExchange.from( - MockServerHttpRequest.get("/").header("X-API-Version", version)); + MockServerHttpRequest.get("/").header("API-Version", version)); Mono result = this.mapping.getHandler(exchange); @@ -82,7 +82,7 @@ public class RouterFunctionMappingVersionTests { @Test void deprecation() { MockServerWebExchange exchange = MockServerWebExchange.from( - MockServerHttpRequest.get("/").header("X-API-Version", "1")); + MockServerHttpRequest.get("/").header("API-Version", "1")); Mono result = this.mapping.getHandler(exchange); @@ -105,7 +105,7 @@ public class RouterFunctionMappingVersionTests { StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); - configurer.useRequestHeader("X-API-Version") + configurer.useRequestHeader("API-Version") .addSupportedVersions("1", "1.1", "1.3") .setDeprecationHandler(handler); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingVersionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingVersionIntegrationTests.java index c80065d55c1..e4be854d953 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingVersionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingVersionIntegrationTests.java @@ -74,7 +74,7 @@ public class RequestMappingVersionIntegrationTests extends AbstractRequestMappin private ResponseEntity exchangeWithVersion(String version) { String url = "http://localhost:" + this.port; - RequestEntity requestEntity = RequestEntity.get(url).header("X-API-Version", version).build(); + RequestEntity requestEntity = RequestEntity.get(url).header("API-Version", version).build(); return getRestTemplate().exchange(requestEntity, String.class); } @@ -88,7 +88,7 @@ public class RequestMappingVersionIntegrationTests extends AbstractRequestMappin StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); - configurer.useRequestHeader("X-API-Version") + configurer.useRequestHeader("API-Version") .addSupportedVersions("1", "1.1", "1.3", "1.6") .setDeprecationHandler(handler); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java index 18db77722bd..8ab56bdafde 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java @@ -394,7 +394,7 @@ class WebMvcConfigurationSupportExtensionTests { @Override public void configureApiVersioning(ApiVersionConfigurer configurer) { - configurer.useRequestHeader("X-API-Version").setVersionRequired(false); + configurer.useRequestHeader("API-Version").setVersionRequired(false); } @Override diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/support/RouterFunctionMappingVersionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/support/RouterFunctionMappingVersionTests.java index ebf4388550a..d6afa45c483 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/support/RouterFunctionMappingVersionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/support/RouterFunctionMappingVersionTests.java @@ -74,7 +74,7 @@ public class RouterFunctionMappingVersionTests { private void testGetHandler(String version, String expectedBody) throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); - request.addHeader("X-API-Version", version); + request.addHeader("API-Version", version); HandlerFunction handler = (HandlerFunction) this.mapping.getHandler(request).getHandler(); assertThat(((TestHandler) handler).body()).isEqualTo(expectedBody); } @@ -82,7 +82,7 @@ public class RouterFunctionMappingVersionTests { @Test void deprecation() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); - request.addHeader("X-API-Version", "1"); + request.addHeader("API-Version", "1"); HandlerExecutionChain chain = this.mapping.getHandler(request); assertThat(chain).isNotNull(); @@ -107,7 +107,7 @@ public class RouterFunctionMappingVersionTests { StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); - configurer.useRequestHeader("X-API-Version") + configurer.useRequestHeader("API-Version") .addSupportedVersions("1", "1.1", "1.3") .setDeprecationHandler(handler); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingVersionHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingVersionHandlerMethodTests.java index 72cfa67e944..018c76df79e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingVersionHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingVersionHandlerMethodTests.java @@ -80,7 +80,7 @@ public class RequestMappingVersionHandlerMethodTests { private MockHttpServletResponse requestWithVersion(String version) throws ServletException, IOException { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); - request.addHeader("X-API-VERSION", version); + request.addHeader("API-Version", version); MockHttpServletResponse response = new MockHttpServletResponse(); this.dispatcherServlet.service(request, response); return response; @@ -96,7 +96,7 @@ public class RequestMappingVersionHandlerMethodTests { StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); - configurer.useRequestHeader("X-API-Version") + configurer.useRequestHeader("API-Version") .addSupportedVersions("1", "1.1", "1.3", "1.6") .setDeprecationHandler(handler); }