Browse Source

Replace X-API-Version with API-Version

Closes gh-35494
pull/35503/head
rstoyanchev 3 months ago
parent
commit
c7121d048c
  1. 4
      framework-docs/modules/ROOT/pages/web/webflux/config.adoc
  2. 2
      framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.java
  3. 2
      framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.kt
  4. 4
      spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ApiVersionTests.java
  5. 4
      spring-test/src/test/java/org/springframework/test/web/servlet/client/samples/ApiVersionTests.java
  6. 8
      spring-web/src/test/java/org/springframework/web/client/RestClientVersionTests.java
  7. 4
      spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java
  8. 8
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientVersionTests.java
  9. 6
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/RouterFunctionMappingVersionTests.java
  10. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingVersionIntegrationTests.java
  11. 2
      spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java
  12. 6
      spring-webmvc/src/test/java/org/springframework/web/servlet/function/support/RouterFunctionMappingVersionTests.java
  13. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingVersionHandlerMethodTests.java

4
framework-docs/modules/ROOT/pages/web/webflux/config.adoc

@ -691,7 +691,7 @@ Java::
@Override @Override
public void configureApiVersioning(ApiVersionConfigurer configurer) { public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.useRequestHeader("X-API-Version"); configurer.useRequestHeader("API-Version");
} }
} }
---- ----
@ -704,7 +704,7 @@ Kotlin::
class WebConfiguration : WebMvcConfigurer { class WebConfiguration : WebMvcConfigurer {
override fun configureApiVersioning(configurer: ApiVersionConfigurer) { override fun configureApiVersioning(configurer: ApiVersionConfigurer) {
configurer.useRequestHeader("X-API-Version") configurer.useRequestHeader("API-Version")
} }
} }
---- ----

2
framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigapiversion/WebConfiguration.java

@ -26,7 +26,7 @@ public class WebConfiguration implements WebMvcConfigurer {
@Override @Override
public void configureApiVersioning(ApiVersionConfigurer configurer) { public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.useRequestHeader("X-API-Version");
} }
configurer.useRequestHeader("API-Version");
} }
// end::snippet[] // end::snippet[]

2
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 { class WebConfiguration : WebMvcConfigurer {
override fun configureApiVersioning(configurer: ApiVersionConfigurer) { override fun configureApiVersioning(configurer: ApiVersionConfigurer) {
configurer.useRequestHeader("X-API-Version") configurer.useRequestHeader("API-Version")
} }
} }
// end::snippet[] // end::snippet[]

4
spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ApiVersionTests.java

@ -40,7 +40,7 @@ public class ApiVersionTests {
@Test @Test
void header() { void header() {
String header = "X-API-Version"; String header = "API-Version";
Map<String, String> result = performRequest( Map<String, String> result = performRequest(
configurer -> configurer.useRequestHeader(header), configurer -> configurer.useRequestHeader(header),
@ -92,7 +92,7 @@ public class ApiVersionTests {
@RestController @RestController
static class TestController { static class TestController {
private static final String HEADER = "X-API-Version"; private static final String HEADER = "API-Version";
@GetMapping(path = "/**", version = "1.2") @GetMapping(path = "/**", version = "1.2")
Map<String, String> handle(ServerHttpRequest request) { Map<String, String> handle(ServerHttpRequest request) {

4
spring-test/src/test/java/org/springframework/test/web/servlet/client/samples/ApiVersionTests.java

@ -44,7 +44,7 @@ public class ApiVersionTests {
@Test @Test
void header() { void header() {
String header = "X-API-Version"; String header = "API-Version";
Map<String, String> result = performRequest( Map<String, String> result = performRequest(
request -> request.getHeader(header), ApiVersionInserter.useHeader(header)); request -> request.getHeader(header), ApiVersionInserter.useHeader(header));
@ -96,7 +96,7 @@ public class ApiVersionTests {
@RestController @RestController
private static class TestController { private static class TestController {
private static final String HEADER = "X-API-Version"; private static final String HEADER = "API-Version";
@GetMapping(path = "/**", version = "1.2") @GetMapping(path = "/**", version = "1.2")
Map<String, String> handle(HttpServletRequest request) { Map<String, String> handle(HttpServletRequest request) {

8
spring-web/src/test/java/org/springframework/web/client/RestClientVersionTests.java

@ -64,8 +64,8 @@ public class RestClientVersionTests {
@Test @Test
void header() { void header() {
performRequest(ApiVersionInserter.useHeader("X-API-Version")); performRequest(ApiVersionInserter.useHeader("API-Version"));
expectRequest(request -> assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2")); expectRequest(request -> assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2"));
} }
@Test @Test
@ -101,11 +101,11 @@ public class RestClientVersionTests {
@Test @Test
void defaultVersion() { 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 restClient = restClientBuilder.defaultApiVersion(1.2).apiVersionInserter(inserter).build();
restClient.get().uri("/path").retrieve().body(String.class); 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) { private void performRequest(ApiVersionInserter versionInserter) {

4
spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java

@ -187,7 +187,7 @@ class RestClientAdapterTests {
RestClient restClient = RestClient.builder() RestClient restClient = RestClient.builder()
.baseUrl(anotherServer.url("/").toString()) .baseUrl(anotherServer.url("/").toString())
.apiVersionInserter(ApiVersionInserter.useHeader("X-API-Version")) .apiVersionInserter(ApiVersionInserter.useHeader("API-Version"))
.build(); .build();
RestClientAdapter adapter = RestClientAdapter.create(restClient); RestClientAdapter adapter = RestClientAdapter.create(restClient);
@ -196,7 +196,7 @@ class RestClientAdapterTests {
String actualResponse = service.getGreetingWithVersion(); String actualResponse = service.getGreetingWithVersion();
RecordedRequest request = anotherServer.takeRequest(); 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!"); assertThat(actualResponse).isEqualTo("Hello Spring 2!");
} }

8
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientVersionTests.java

@ -61,8 +61,8 @@ public class WebClientVersionTests {
@Test @Test
void header() { void header() {
performRequest(ApiVersionInserter.useHeader("X-API-Version")); performRequest(ApiVersionInserter.useHeader("API-Version"));
expectRequest(request -> assertThat(request.getHeaders().get("X-API-Version")).isEqualTo("1.2")); expectRequest(request -> assertThat(request.getHeaders().get("API-Version")).isEqualTo("1.2"));
} }
@Test @Test
@ -92,11 +92,11 @@ public class WebClientVersionTests {
@Test @Test
void defaultVersion() { 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 webClient = webClientBuilder.defaultApiVersion(1.2).apiVersionInserter(inserter).build();
webClient.get().uri("/path").retrieve().bodyToMono(String.class).block(); 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) { private void performRequest(ApiVersionInserter versionInserter) {

6
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) { private void testGetHandler(String version, String expectedBody) {
MockServerWebExchange exchange = MockServerWebExchange.from( MockServerWebExchange exchange = MockServerWebExchange.from(
MockServerHttpRequest.get("/").header("X-API-Version", version)); MockServerHttpRequest.get("/").header("API-Version", version));
Mono<?> result = this.mapping.getHandler(exchange); Mono<?> result = this.mapping.getHandler(exchange);
@ -82,7 +82,7 @@ public class RouterFunctionMappingVersionTests {
@Test @Test
void deprecation() { void deprecation() {
MockServerWebExchange exchange = MockServerWebExchange.from( MockServerWebExchange exchange = MockServerWebExchange.from(
MockServerHttpRequest.get("/").header("X-API-Version", "1")); MockServerHttpRequest.get("/").header("API-Version", "1"));
Mono<?> result = this.mapping.getHandler(exchange); Mono<?> result = this.mapping.getHandler(exchange);
@ -105,7 +105,7 @@ public class RouterFunctionMappingVersionTests {
StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler();
handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); 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") .addSupportedVersions("1", "1.1", "1.3")
.setDeprecationHandler(handler); .setDeprecationHandler(handler);
} }

4
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<String> exchangeWithVersion(String version) { private ResponseEntity<String> exchangeWithVersion(String version) {
String url = "http://localhost:" + this.port; String url = "http://localhost:" + this.port;
RequestEntity<Void> requestEntity = RequestEntity.get(url).header("X-API-Version", version).build(); RequestEntity<Void> requestEntity = RequestEntity.get(url).header("API-Version", version).build();
return getRestTemplate().exchange(requestEntity, String.class); return getRestTemplate().exchange(requestEntity, String.class);
} }
@ -88,7 +88,7 @@ public class RequestMappingVersionIntegrationTests extends AbstractRequestMappin
StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler();
handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); 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") .addSupportedVersions("1", "1.1", "1.3", "1.6")
.setDeprecationHandler(handler); .setDeprecationHandler(handler);
} }

2
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java

@ -394,7 +394,7 @@ class WebMvcConfigurationSupportExtensionTests {
@Override @Override
public void configureApiVersioning(ApiVersionConfigurer configurer) { public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.useRequestHeader("X-API-Version").setVersionRequired(false); configurer.useRequestHeader("API-Version").setVersionRequired(false);
} }
@Override @Override

6
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 { private void testGetHandler(String version, String expectedBody) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.addHeader("X-API-Version", version); request.addHeader("API-Version", version);
HandlerFunction<?> handler = (HandlerFunction<?>) this.mapping.getHandler(request).getHandler(); HandlerFunction<?> handler = (HandlerFunction<?>) this.mapping.getHandler(request).getHandler();
assertThat(((TestHandler) handler).body()).isEqualTo(expectedBody); assertThat(((TestHandler) handler).body()).isEqualTo(expectedBody);
} }
@ -82,7 +82,7 @@ public class RouterFunctionMappingVersionTests {
@Test @Test
void deprecation() throws Exception { void deprecation() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.addHeader("X-API-Version", "1"); request.addHeader("API-Version", "1");
HandlerExecutionChain chain = this.mapping.getHandler(request); HandlerExecutionChain chain = this.mapping.getHandler(request);
assertThat(chain).isNotNull(); assertThat(chain).isNotNull();
@ -107,7 +107,7 @@ public class RouterFunctionMappingVersionTests {
StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler();
handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); 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") .addSupportedVersions("1", "1.1", "1.3")
.setDeprecationHandler(handler); .setDeprecationHandler(handler);
} }

4
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 { private MockHttpServletResponse requestWithVersion(String version) throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.addHeader("X-API-VERSION", version); request.addHeader("API-Version", version);
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
this.dispatcherServlet.service(request, response); this.dispatcherServlet.service(request, response);
return response; return response;
@ -96,7 +96,7 @@ public class RequestMappingVersionHandlerMethodTests {
StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler(); StandardApiVersionDeprecationHandler handler = new StandardApiVersionDeprecationHandler();
handler.configureVersion("1").setDeprecationLink(URI.create("https://example.org/deprecation")); 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") .addSupportedVersions("1", "1.1", "1.3", "1.6")
.setDeprecationHandler(handler); .setDeprecationHandler(handler);
} }

Loading…
Cancel
Save