Add MediaType parameter to ApiVersionInserter

Closes gh-35259
This commit is contained in:
rstoyanchev
2025-07-31 14:58:26 +01:00
parent 08ccf46399
commit da361699a4
4 changed files with 65 additions and 28 deletions
@@ -26,6 +26,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import static org.assertj.core.api.Assertions.assertThat;
@@ -73,6 +74,12 @@ public class RestClientVersionTests {
expectRequest(request -> assertThat(request.getTarget()).isEqualTo("/path?api-version=1.2"));
}
@Test
void mediaTypeParam() {
performRequest(ApiVersionInserter.useMediaTypeParam("v"));
expectRequest(request -> assertThat(request.getHeaders().get("Content-Type")).isEqualTo("application/json;v=1.2"));
}
@Test
void pathSegmentIndexLessThanSize() {
performRequest(ApiVersionInserter.builder().usePathSegment(0).withVersionFormatter(v -> "v" + v).build());
@@ -103,7 +110,8 @@ public class RestClientVersionTests {
private void performRequest(ApiVersionInserter versionInserter) {
restClientBuilder.apiVersionInserter(versionInserter).build()
.get().uri("/path")
.post().uri("/path")
.contentType(MediaType.APPLICATION_JSON)
.apiVersion(1.2)
.retrieve()
.body(String.class);