Skip to content

Commit a502f4d

Browse files
committed
Use spring.restdocs as prefix for Spring REST Docs properties
Closes gh-47481
1 parent e6e0db0 commit a502f4d

File tree

6 files changed

+95
-41
lines changed

6 files changed

+95
-41
lines changed

module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/AutoConfigureRestDocs.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
@Inherited
5959
@ImportAutoConfiguration
6060
@Import(RestDocumentationContextProviderRegistrar.class)
61-
@PropertyMapping("spring.test.restdocs")
61+
@PropertyMapping("spring.restdocs")
6262
public @interface AutoConfigureRestDocs {
6363

6464
/**
@@ -82,18 +82,21 @@
8282
* Defaults to {@code http}.
8383
* @return the scheme
8484
*/
85+
@PropertyMapping("uri.scheme")
8586
String uriScheme() default "http";
8687

8788
/**
8889
* The host to be used in documented URIs. Defaults to {@code localhost}.
8990
* @return the host
9091
*/
92+
@PropertyMapping("uri.host")
9193
String uriHost() default "localhost";
9294

9395
/**
9496
* The port to be used in documented URIs. Defaults to {@code 8080}.
9597
* @return the port
9698
*/
99+
@PropertyMapping("uri.port")
97100
int uriPort() default 8080;
98101

99102
}

module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsMockMvcBuilderCustomizer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.beans.factory.InitializingBean;
2222
import org.springframework.boot.context.properties.PropertyMapper;
23+
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties.Uri;
2324
import org.springframework.boot.webmvc.test.autoconfigure.MockMvcBuilderCustomizer;
2425
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer;
2526
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
@@ -51,10 +52,11 @@ public class RestDocsMockMvcBuilderCustomizer implements InitializingBean, MockM
5152
public void afterPropertiesSet() throws Exception {
5253
PropertyMapper map = PropertyMapper.get();
5354
RestDocsProperties properties = this.properties;
54-
UriConfigurer uri = this.delegate.uris();
55-
map.from(properties::getUriScheme).whenHasText().to(uri::withScheme);
56-
map.from(properties::getUriHost).whenHasText().to(uri::withHost);
57-
map.from(properties::getUriPort).to(uri::withPort);
55+
UriConfigurer uriConfigurer = this.delegate.uris();
56+
Uri uri = properties.getUri();
57+
map.from(uri::getScheme).whenHasText().to(uriConfigurer::withScheme);
58+
map.from(uri::getHost).whenHasText().to(uriConfigurer::withHost);
59+
map.from(uri::getPort).to(uriConfigurer::withPort);
5860
}
5961

6062
@Override

module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsProperties.java

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,56 @@
2828
* @author Phillip Webb
2929
* @since 4.0.0
3030
*/
31-
@ConfigurationProperties("spring.test.restdocs")
31+
@ConfigurationProperties("spring.restdocs")
3232
public class RestDocsProperties {
3333

34-
/**
35-
* The URI scheme for to use (for example http).
36-
*/
37-
private @Nullable String uriScheme;
34+
private final Uri uri = new Uri();
3835

39-
/**
40-
* The URI host to use.
41-
*/
42-
private @Nullable String uriHost;
36+
public Uri getUri() {
37+
return this.uri;
38+
}
4339

44-
/**
45-
* The URI port to use.
46-
*/
47-
private @Nullable Integer uriPort;
40+
public static class Uri {
4841

49-
public @Nullable String getUriScheme() {
50-
return this.uriScheme;
51-
}
42+
/**
43+
* The URI scheme to use (for example http).
44+
*/
45+
private @Nullable String scheme;
5246

53-
public void setUriScheme(@Nullable String uriScheme) {
54-
this.uriScheme = uriScheme;
55-
}
47+
/**
48+
* The URI host to use.
49+
*/
50+
private @Nullable String host;
5651

57-
public @Nullable String getUriHost() {
58-
return this.uriHost;
59-
}
52+
/**
53+
* The URI port to use.
54+
*/
55+
private @Nullable Integer port;
6056

61-
public void setUriHost(@Nullable String uriHost) {
62-
this.uriHost = uriHost;
63-
}
57+
public @Nullable String getScheme() {
58+
return this.scheme;
59+
}
6460

65-
public @Nullable Integer getUriPort() {
66-
return this.uriPort;
67-
}
61+
public void setScheme(@Nullable String scheme) {
62+
this.scheme = scheme;
63+
}
64+
65+
public @Nullable String getHost() {
66+
return this.host;
67+
}
68+
69+
public void setHost(@Nullable String host) {
70+
this.host = host;
71+
}
72+
73+
public @Nullable Integer getPort() {
74+
return this.port;
75+
}
76+
77+
public void setPort(@Nullable Integer port) {
78+
this.port = port;
79+
}
6880

69-
public void setUriPort(@Nullable Integer uriPort) {
70-
this.uriPort = uriPort;
7181
}
7282

7383
}

module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsRestAssuredBuilderCustomizer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.beans.factory.InitializingBean;
2222
import org.springframework.boot.context.properties.PropertyMapper;
23+
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties.Uri;
2324
import org.springframework.util.StringUtils;
2425

2526
/**
@@ -41,11 +42,12 @@ class RestDocsRestAssuredBuilderCustomizer implements InitializingBean {
4142
@Override
4243
public void afterPropertiesSet() throws Exception {
4344
PropertyMapper map = PropertyMapper.get();
44-
String host = this.properties.getUriHost();
45-
map.from(this.properties::getUriScheme)
45+
Uri uri = this.properties.getUri();
46+
String host = uri.getHost();
47+
map.from(uri::getScheme)
4648
.when((scheme) -> StringUtils.hasText(scheme) && StringUtils.hasText(host))
4749
.to((scheme) -> this.delegate.baseUri(scheme + "://" + host));
48-
map.from(this.properties::getUriPort).to(this.delegate::port);
50+
map.from(uri::getPort).to(this.delegate::port);
4951
}
5052

5153
}

module/spring-boot-restdocs/src/main/java/org/springframework/boot/restdocs/test/autoconfigure/RestDocsWebTestClientBuilderCustomizer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.jspecify.annotations.Nullable;
2020

21+
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties.Uri;
2122
import org.springframework.boot.webtestclient.WebTestClientBuilderCustomizer;
2223
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer;
2324
import org.springframework.test.web.reactive.server.WebTestClient;
@@ -48,11 +49,12 @@ public void customize(WebTestClient.Builder builder) {
4849
}
4950

5051
private void customizeBaseUrl(WebTestClient.Builder builder) {
51-
String scheme = this.properties.getUriScheme();
52-
String host = this.properties.getUriHost();
52+
Uri uri = this.properties.getUri();
53+
String scheme = uri.getScheme();
54+
String host = uri.getHost();
5355
String baseUrl = (StringUtils.hasText(scheme) ? scheme : "http") + "://"
5456
+ (StringUtils.hasText(host) ? host : "localhost");
55-
Integer port = this.properties.getUriPort();
57+
Integer port = uri.getPort();
5658
if (!isStandardPort(scheme, port)) {
5759
baseUrl += ":" + port;
5860
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"properties": [
3+
{
4+
"name": "spring.test.restdocs.uri-host",
5+
"type": "java.lang.String",
6+
"description": "The URI host to use.",
7+
"sourceType": "org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties",
8+
"deprecation": {
9+
"level": "error",
10+
"replacement": "spring.restdocs.uri.host"
11+
}
12+
},
13+
{
14+
"name": "spring.test.restdocs.uri-port",
15+
"type": "java.lang.Integer",
16+
"description": "The URI port to use.",
17+
"sourceType": "org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties",
18+
"deprecation": {
19+
"level": "error",
20+
"replacement": "spring.restdocs.uri.port"
21+
}
22+
23+
},
24+
{
25+
"name": "spring.test.restdocs.uri-scheme",
26+
"type": "java.lang.String",
27+
"description": "The URI scheme to use (for example http).",
28+
"sourceType": "org.springframework.boot.restdocs.test.autoconfigure.RestDocsProperties",
29+
"deprecation": {
30+
"level": "error",
31+
"replacement": "spring.restdocs.uri.scheme"
32+
}
33+
}
34+
]
35+
}

0 commit comments

Comments
 (0)