Skip to content

Commit a8652a8

Browse files
committed
Merge pull request spring-projects#27755 from brneto
* spring-projectsgh-27755: Polish "Document how to parameterize REST Docs' output dir with WebTestClient" Document how to parameterize REST Docs' output dir with WebTestClient Closes spring-projectsgh-27755
2 parents f8ef908 + 990b766 commit a8652a8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8063,6 +8063,14 @@ If you require more control over Spring REST Docs configuration than offered by
80638063
include::{code-examples}/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java[tag=configuration]
80648064
----
80658065

8066+
If you want to make use of Spring REST Docs support for a parameterized output directory, you can use a `WebTestClientBuilderCustomizer` to configure a consumer for every entity exchange result.
8067+
The following example shows such a `WebTestClientBuilderCustomizer` being defined:
8068+
8069+
[source,java,indent=0]
8070+
----
8071+
include::{code-examples}/test/autoconfigure/restdocs/webclient/ParameterizedOutputConfigurationExample.java[tag=configuration]
8072+
----
8073+
80668074

80678075

80688076
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs-rest-assured]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient;
18+
19+
import org.springframework.boot.test.context.TestConfiguration;
20+
import org.springframework.boot.test.web.reactive.server.WebTestClientBuilderCustomizer;
21+
import org.springframework.context.annotation.Bean;
22+
23+
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
24+
25+
class ParameterizedOutputConfigurationExample {
26+
27+
// tag::configuration[]
28+
@TestConfiguration(proxyBeanMethods = false)
29+
static class ParameterizedOutputConfiguration {
30+
31+
@Bean
32+
WebTestClientBuilderCustomizer restDocumentation() {
33+
return (builder) -> builder.entityExchangeResultConsumer(document("{method-name}"));
34+
}
35+
36+
}
37+
// end::configuration[]
38+
39+
}

0 commit comments

Comments
 (0)