mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Versioning support in WebTestClient controller setup
See gh-34919
This commit is contained in:
+17
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.reactive.config.ApiVersionConfigurer;
|
||||
import org.springframework.web.reactive.config.BlockingExecutionConfigurer;
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
import org.springframework.web.reactive.config.DelegatingWebFluxConfiguration;
|
||||
@@ -118,6 +119,12 @@ class DefaultControllerSpec extends AbstractMockServerSpec<WebTestClient.Control
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebTestClient.ControllerSpec apiVersioning(Consumer<ApiVersionConfigurer> configurer) {
|
||||
this.configurer.versionConsumer = configurer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultControllerSpec viewResolvers(Consumer<ViewResolverRegistry> consumer) {
|
||||
this.configurer.viewResolversConsumer = consumer;
|
||||
@@ -168,6 +175,8 @@ class DefaultControllerSpec extends AbstractMockServerSpec<WebTestClient.Control
|
||||
|
||||
private @Nullable Validator validator;
|
||||
|
||||
private @Nullable Consumer<ApiVersionConfigurer> versionConsumer;
|
||||
|
||||
private @Nullable Consumer<ViewResolverRegistry> viewResolversConsumer;
|
||||
|
||||
private @Nullable Consumer<BlockingExecutionConfigurer> executionConsumer;
|
||||
@@ -219,6 +228,13 @@ class DefaultControllerSpec extends AbstractMockServerSpec<WebTestClient.Control
|
||||
return this.validator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureApiVersioning(ApiVersionConfigurer configurer) {
|
||||
if (this.versionConsumer != null) {
|
||||
this.versionConsumer.accept(configurer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
if (this.viewResolversConsumer != null) {
|
||||
|
||||
+7
@@ -48,6 +48,7 @@ import org.springframework.validation.Validator;
|
||||
import org.springframework.web.client.ApiVersionFormatter;
|
||||
import org.springframework.web.client.ApiVersionInserter;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.reactive.config.ApiVersionConfigurer;
|
||||
import org.springframework.web.reactive.config.BlockingExecutionConfigurer;
|
||||
import org.springframework.web.reactive.config.CorsRegistry;
|
||||
import org.springframework.web.reactive.config.PathMatchConfigurer;
|
||||
@@ -346,6 +347,12 @@ public interface WebTestClient {
|
||||
*/
|
||||
ControllerSpec validator(Validator validator);
|
||||
|
||||
/**
|
||||
* Configure API versioning for mapping requests to controller methods.
|
||||
* @since 7.0
|
||||
*/
|
||||
ControllerSpec apiVersioning(Consumer<ApiVersionConfigurer> configurer);
|
||||
|
||||
/**
|
||||
* Configure view resolution.
|
||||
* @see WebFluxConfigurer#configureViewResolvers
|
||||
|
||||
Reference in New Issue
Block a user