diff --git a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/AutoConfigureRestDocs.java b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/AutoConfigureRestDocs.java index 8c01d8ed96c..2a4d0a95c48 100644 --- a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/AutoConfigureRestDocs.java +++ b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/AutoConfigureRestDocs.java @@ -58,7 +58,7 @@ import org.springframework.test.web.servlet.MockMvc; @Inherited @ImportAutoConfiguration @Import(RestDocumentationContextProviderRegistrar.class) -@PropertyMapping("spring.test.restdocs") +@PropertyMapping("spring.restdocs") public @interface AutoConfigureRestDocs { /** @@ -82,18 +82,21 @@ public @interface AutoConfigureRestDocs { * Defaults to {@code http}. * @return the scheme */ + @PropertyMapping("uri.scheme") String uriScheme() default "http"; /** * The host to be used in documented URIs. Defaults to {@code localhost}. * @return the host */ + @PropertyMapping("uri.host") String uriHost() default "localhost"; /** * The port to be used in documented URIs. Defaults to {@code 8080}. * @return the port */ + @PropertyMapping("uri.port") int uriPort() default 8080; } diff --git a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsMockMvcBuilderCustomizer.java b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsMockMvcBuilderCustomizer.java index f75622acdfd..c801707cb50 100644 --- a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsMockMvcBuilderCustomizer.java +++ b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsMockMvcBuilderCustomizer.java @@ -20,6 +20,7 @@ import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.properties.PropertyMapper; +import org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties.Uri; import org.springframework.boot.webmvc.test.autoconfigure.MockMvcBuilderCustomizer; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; @@ -51,10 +52,11 @@ public class RestDocsMockMvcBuilderCustomizer implements InitializingBean, MockM public void afterPropertiesSet() throws Exception { PropertyMapper map = PropertyMapper.get(); RestDocsProperties properties = this.properties; - UriConfigurer uri = this.delegate.uris(); - map.from(properties::getUriScheme).whenHasText().to(uri::withScheme); - map.from(properties::getUriHost).whenHasText().to(uri::withHost); - map.from(properties::getUriPort).to(uri::withPort); + UriConfigurer uriConfigurer = this.delegate.uris(); + Uri uri = properties.getUri(); + map.from(uri::getScheme).whenHasText().to(uriConfigurer::withScheme); + map.from(uri::getHost).whenHasText().to(uriConfigurer::withHost); + map.from(uri::getPort).to(uriConfigurer::withPort); } @Override diff --git a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsProperties.java b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsProperties.java index 6b9d4a4568a..7274789d79b 100644 --- a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsProperties.java +++ b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsProperties.java @@ -28,46 +28,56 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Phillip Webb * @since 4.0.0 */ -@ConfigurationProperties("spring.test.restdocs") +@ConfigurationProperties("spring.restdocs") public class RestDocsProperties { - /** - * The URI scheme for to use (for example http). - */ - private @Nullable String uriScheme; + private final Uri uri = new Uri(); - /** - * The URI host to use. - */ - private @Nullable String uriHost; - - /** - * The URI port to use. - */ - private @Nullable Integer uriPort; - - public @Nullable String getUriScheme() { - return this.uriScheme; + public Uri getUri() { + return this.uri; } - public void setUriScheme(@Nullable String uriScheme) { - this.uriScheme = uriScheme; - } + public static class Uri { - public @Nullable String getUriHost() { - return this.uriHost; - } + /** + * The URI scheme to use (for example http). + */ + private @Nullable String scheme; - public void setUriHost(@Nullable String uriHost) { - this.uriHost = uriHost; - } + /** + * The URI host to use. + */ + private @Nullable String host; - public @Nullable Integer getUriPort() { - return this.uriPort; - } + /** + * The URI port to use. + */ + private @Nullable Integer port; + + public @Nullable String getScheme() { + return this.scheme; + } + + public void setScheme(@Nullable String scheme) { + this.scheme = scheme; + } + + public @Nullable String getHost() { + return this.host; + } + + public void setHost(@Nullable String host) { + this.host = host; + } + + public @Nullable Integer getPort() { + return this.port; + } + + public void setPort(@Nullable Integer port) { + this.port = port; + } - public void setUriPort(@Nullable Integer uriPort) { - this.uriPort = uriPort; } } diff --git a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsRestAssuredBuilderCustomizer.java b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsRestAssuredBuilderCustomizer.java index ce6c7ca0348..cc607d5c0a9 100644 --- a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsRestAssuredBuilderCustomizer.java +++ b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsRestAssuredBuilderCustomizer.java @@ -20,6 +20,7 @@ import io.restassured.specification.RequestSpecification; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.properties.PropertyMapper; +import org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties.Uri; import org.springframework.util.StringUtils; /** @@ -41,11 +42,12 @@ class RestDocsRestAssuredBuilderCustomizer implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { PropertyMapper map = PropertyMapper.get(); - String host = this.properties.getUriHost(); - map.from(this.properties::getUriScheme) + Uri uri = this.properties.getUri(); + String host = uri.getHost(); + map.from(uri::getScheme) .when((scheme) -> StringUtils.hasText(scheme) && StringUtils.hasText(host)) .to((scheme) -> this.delegate.baseUri(scheme + "://" + host)); - map.from(this.properties::getUriPort).to(this.delegate::port); + map.from(uri::getPort).to(this.delegate::port); } } diff --git a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsWebTestClientBuilderCustomizer.java b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsWebTestClientBuilderCustomizer.java index 370c1fa7c32..cf292b56e71 100644 --- a/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsWebTestClientBuilderCustomizer.java +++ b/module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsWebTestClientBuilderCustomizer.java @@ -18,6 +18,7 @@ package org.springframework.boot.restdocs.test.autoconfigure; import org.jspecify.annotations.Nullable; +import org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties.Uri; import org.springframework.boot.webtestclient.WebTestClientBuilderCustomizer; import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer; import org.springframework.test.web.reactive.server.WebTestClient; @@ -48,11 +49,12 @@ class RestDocsWebTestClientBuilderCustomizer implements WebTestClientBuilderCust } private void customizeBaseUrl(WebTestClient.Builder builder) { - String scheme = this.properties.getUriScheme(); - String host = this.properties.getUriHost(); + Uri uri = this.properties.getUri(); + String scheme = uri.getScheme(); + String host = uri.getHost(); String baseUrl = (StringUtils.hasText(scheme) ? scheme : "http") + "://" + (StringUtils.hasText(host) ? host : "localhost"); - Integer port = this.properties.getUriPort(); + Integer port = uri.getPort(); if (!isStandardPort(scheme, port)) { baseUrl += ":" + port; } diff --git a/module/spring-boot-restdocs/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/module/spring-boot-restdocs/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000000..34dccb48c77 --- /dev/null +++ b/module/spring-boot-restdocs/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,35 @@ +{ + "properties": [ + { + "name": "spring.test.restdocs.uri-host", + "type": "java.lang.String", + "description": "The URI host to use.", + "sourceType": "org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties", + "deprecation": { + "level": "error", + "replacement": "spring.restdocs.uri.host" + } + }, + { + "name": "spring.test.restdocs.uri-port", + "type": "java.lang.Integer", + "description": "The URI port to use.", + "sourceType": "org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties", + "deprecation": { + "level": "error", + "replacement": "spring.restdocs.uri.port" + } + + }, + { + "name": "spring.test.restdocs.uri-scheme", + "type": "java.lang.String", + "description": "The URI scheme to use (for example http).", + "sourceType": "org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties", + "deprecation": { + "level": "error", + "replacement": "spring.restdocs.uri.scheme" + } + } + ] +} \ No newline at end of file