Skip to content

Commit 54d1210

Browse files
committed
Document parameterized output with WebTestClient
Closes gh-713
1 parent 55cbdd5 commit 54d1210

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

docs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616
asciidoctorExt("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.5.0")
1717

1818
internal(platform(project(":spring-restdocs-platform")))
19+
internal(enforcedPlatform("org.springframework:spring-framework-bom:5.3.8"))
1920

2021
testImplementation(project(":spring-restdocs-mockmvc"))
2122
testImplementation(project(":spring-restdocs-restassured"))

docs/src/docs/asciidoc/documenting-your-api.adoc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,8 +1317,8 @@ You can configure which snippets are produced by default. See the
13171317
[[documentating-your-api-parameterized-output-directories]]
13181318
=== Using Parameterized Output Directories
13191319

1320-
When using MockMvc or REST Assured, you can parameterize the output directory used by
1321-
`document`. You cannot parameterize the output directory when using `WebTestClient`.
1320+
When using MockMvc, REST Assured, or `WebTestClient` you can parameterize the output directory used by
1321+
`document`. Parameterizing output with `WebTestClient` requires Spring Framework 5.3.5 or later.
13221322

13231323
The following parameters are supported:
13241324

@@ -1368,6 +1368,12 @@ include::{examples-dir}/com/example/mockmvc/ParameterizedOutput.java[tags=parame
13681368
----
13691369
include::{examples-dir}/com/example/restassured/ParameterizedOutput.java[tags=parameterized-output]
13701370
----
1371+
1372+
[source,java,indent=0,role="secondary"]
1373+
.WebTestClient
1374+
----
1375+
include::{examples-dir}/com/example/webtestclient/ParameterizedOutput.java[tags=parameterized-output]
1376+
----
13711377
====
13721378

13731379
With this configuration in place, every call to the service you are testing produces
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2014-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 com.example.webtestclient;
18+
19+
import org.junit.Before;
20+
import org.junit.Rule;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.context.ApplicationContext;
24+
import org.springframework.restdocs.JUnitRestDocumentation;
25+
import org.springframework.test.web.reactive.server.WebTestClient;
26+
27+
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
28+
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.documentationConfiguration;
29+
30+
public class ParameterizedOutput {
31+
32+
@Rule
33+
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
34+
35+
@SuppressWarnings("unused")
36+
private WebTestClient webTestClient;
37+
38+
@Autowired
39+
private ApplicationContext context;
40+
41+
// tag::parameterized-output[]
42+
@Before
43+
public void setUp() {
44+
this.webTestClient = WebTestClient.bindToApplicationContext(this.context)
45+
.configureClient()
46+
.filter(documentationConfiguration(this.restDocumentation))
47+
.entityExchangeResultConsumer(document("{method-name}/{step}"))
48+
.build();
49+
}
50+
// end::parameterized-output[]
51+
52+
}

0 commit comments

Comments
 (0)