1
1
[[configuration]]
2
2
== Configuration
3
3
4
-
4
+ This section covers how to configure Spring REST Docs.
5
5
6
6
[[configuration-uris]]
7
7
=== Documented URIs
8
8
9
-
9
+ This section covers configuring documented URIs.
10
10
11
11
[[configuration-uris-mockmvc]]
12
- ==== MockMvc URI customization
12
+ ==== MockMvc URI Customization
13
13
14
- When using MockMvc, the default configuration for URIs documented by Spring REST Docs is:
14
+ When using MockMvc, the default configuration for URIs documented by Spring REST Docs is
15
+ as follows:
15
16
16
17
|===
17
18
|Setting |Default
@@ -26,54 +27,63 @@ When using MockMvc, the default configuration for URIs documented by Spring REST
26
27
|`8080`
27
28
|===
28
29
29
- This configuration is applied by `MockMvcRestDocumentationConfigurer`. You can use its API
30
- to change one or more of the defaults to suit your needs:
30
+ This configuration is applied by `MockMvcRestDocumentationConfigurer`. You can use its
31
+ API to change one or more of the defaults to suit your needs. The following example shows
32
+ how to do so:
31
33
34
+ ====
32
35
[source,java,indent=0]
33
36
----
34
37
include::{examples-dir}/com/example/mockmvc/CustomUriConfiguration.java[tags=custom-uri-configuration]
35
38
----
39
+ ====
36
40
37
41
NOTE: If the port is set to the default for the configured scheme (port 80 for HTTP or
38
- port 443 for HTTPS), it will be omitted from any URIs in the generated snippets.
42
+ port 443 for HTTPS), it is omitted from any URIs in the generated snippets.
39
43
40
44
TIP: To configure a request's context path, use the `contextPath` method on
41
45
`MockHttpServletRequestBuilder`.
42
46
43
47
44
48
45
49
[[configuration-uris-rest-assured]]
46
- ==== REST Assured URI customization
50
+ ==== REST Assured URI Customization
47
51
48
52
REST Assured tests a service by making actual HTTP requests. As a result, URIs must be
49
53
customized once the operation on the service has been performed but before it is
50
- documented. A <<customizing-requests-and-responses-preprocessors-modify-uris, REST-Assured
51
- specific preprocessor>> is provided for this purpose.
54
+ documented. A
55
+ <<customizing-requests-and-responses-preprocessors-modify-uris, REST-Assured-specific
56
+ preprocessor>> is provided for this purpose.
52
57
53
58
54
59
55
60
[[configuration-uris-webtestclient]]
56
- ==== WebTestClient URI customization
61
+ ==== WebTestClient URI Customization
57
62
58
63
When using WebTestClient, the default base for URIs documented by Spring REST
59
- Docs is `http://localhost:8080`. This base can be customized using the
64
+ Docs is `http://localhost:8080`. You can customize this base by using the
60
65
{spring-framework-api}/org/springframework/test/web/reactive/server/WebTestClient.Builder.html#baseUrl-java.lang.String-[
61
- `baseUrl(String)` method on `WebTestClient.Builder`]:
66
+ `baseUrl(String)` method on `WebTestClient.Builder`]. The following example shows how to
67
+ do so:
62
68
69
+ ====
63
70
[source,java,indent=0]
64
71
----
65
72
include::{examples-dir}/com/example/webtestclient/CustomUriConfiguration.java[tags=custom-uri-configuration]
66
73
----
67
74
<1> Configure the base of documented URIs to be `https://api.example.com`.
75
+ ====
68
76
69
77
70
78
71
79
[[configuration-snippet-encoding]]
72
- === Snippet encoding
80
+ === Snippet Encoding
73
81
74
- The default snippet encoding is `UTF-8`. You can change the default snippet encoding
75
- using the `RestDocumentationConfigurer` API. For example, to use `ISO-8859-1`:
82
+ The default snippet encoding is `UTF-8`. You can change the default snippet encoding by
83
+ using the `RestDocumentationConfigurer` API. For example, the following examples use
84
+ `ISO-8859-1`:
76
85
86
+ ====
77
87
[source,java,indent=0,role="primary"]
78
88
.MockMvc
79
89
----
@@ -91,20 +101,23 @@ include::{examples-dir}/com/example/webtestclient/CustomEncoding.java[tags=custo
91
101
----
92
102
include::{examples-dir}/com/example/restassured/CustomEncoding.java[tags=custom-encoding]
93
103
----
104
+ ====
94
105
95
- TIP: When Spring REST Docs converts a request or response's content to a String, the
96
- `charset` specified in the `Content-Type` header will be used if it is available. In its
97
- absence, the JVM's default `Charset` will be used. The JVM's default `Charset` can be
98
- configured using the `file.encoding` system property.
106
+ TIP: When Spring REST Docs converts the content of a request or a response to a ` String`,
107
+ the `charset` specified in the `Content-Type` header is used if it is available. In its
108
+ absence, the JVM's default `Charset` is used. You can configure the JVM's default
109
+ `Charset` byusing the `file.encoding` system property.
99
110
100
111
101
112
102
113
[[configuration-snippet-template-format]]
103
- === Snippet template format
114
+ === Snippet Template Format
104
115
105
116
The default snippet template format is Asciidoctor. Markdown is also supported out of the
106
- box. You can change the default format using the `RestDocumentationConfigurer` API:
117
+ box. You can change the default format by using the `RestDocumentationConfigurer` API.
118
+ The following examples show how to do so:
107
119
120
+ ====
108
121
[source,java,indent=0,role="primary"]
109
122
.MockMvc
110
123
----
@@ -122,25 +135,27 @@ include::{examples-dir}/com/example/webtestclient/CustomFormat.java[tags=custom-
122
135
----
123
136
include::{examples-dir}/com/example/restassured/CustomFormat.java[tags=custom-format]
124
137
----
138
+ ====
125
139
126
140
127
141
128
142
[[configuration-default-snippets]]
129
- === Default snippets
143
+ === Default Snippets
130
144
131
145
Six snippets are produced by default:
132
146
133
- - `curl-request`
134
- - `http-request`
135
- - `http-response`
136
- - `httpie-request`
137
- - `request-body`
138
- - `response-body`
147
+ * `curl-request`
148
+ * `http-request`
149
+ * `http-response`
150
+ * `httpie-request`
151
+ * `request-body`
152
+ * `response-body`
139
153
140
- You can change the default snippet configuration during setup using the
141
- `RestDocumentationConfigurer` API. For example, to only produce the `curl-request`
154
+ You can change the default snippet configuration during setup by using the
155
+ `RestDocumentationConfigurer` API. The following examples produce only the `curl-request`
142
156
snippet by default:
143
157
158
+ ====
144
159
[source,java,indent=0,role="primary"]
145
160
.MockMvc
146
161
----
@@ -158,35 +173,37 @@ include::{examples-dir}/com/example/webtestclient/CustomDefaultSnippets.java[tag
158
173
----
159
174
include::{examples-dir}/com/example/restassured/CustomDefaultSnippets.java[tags=custom-default-snippets]
160
175
----
176
+ ====
161
177
162
178
[[configuration-default-preprocessors]]
163
- === Default operation preprocessors
179
+ === Default Operation Preprocessors
164
180
165
- You can configure default request and response preprocessors during setup using the
166
- `RestDocumentationConfigurer` API. For example, to remove the `Foo` headers from all requests
167
- and pretty print all responses:
181
+ You can configure default request and response preprocessors during setup by using the
182
+ `RestDocumentationConfigurer` API. The following examples remove the `Foo` headers from
183
+ all requests and pretty print all responses:
168
184
185
+ ====
169
186
[source,java,indent=0,role="primary"]
170
187
.MockMvc
171
188
----
172
189
include::{examples-dir}/com/example/mockmvc/CustomDefaultOperationPreprocessors.java[tags=custom-default-operation-preprocessors]
173
190
----
174
- <1> Apply a request preprocessor that will remove the header named `Foo`.
175
- <2> Apply a response preprocessor that will pretty print its content.
191
+ <1> Apply a request preprocessor that removes the header named `Foo`.
192
+ <2> Apply a response preprocessor that pretty prints its content.
176
193
177
194
[source,java,indent=0,role="secondary"]
178
195
.WebTestClient
179
196
----
180
197
include::{examples-dir}/com/example/webtestclient/CustomDefaultOperationPreprocessors.java[tags=custom-default-operation-preprocessors]
181
198
----
182
- <1> Apply a request preprocessor that will remove the header named `Foo`.
183
- <2> Apply a response preprocessor that will pretty print its content.
199
+ <1> Apply a request preprocessor that removes the header named `Foo`.
200
+ <2> Apply a response preprocessor that pretty prints its content.
184
201
185
202
[source,java,indent=0,role="secondary"]
186
203
.REST Assured
187
204
----
188
205
include::{examples-dir}/com/example/restassured/CustomDefaultOperationPreprocessors.java[tags=custom-default-operation-preprocessors]
189
206
----
190
- <1> Apply a request preprocessor that will remove the header named `Foo`.
191
- <2> Apply a response preprocessor that will pretty print its content.
192
-
207
+ <1> Apply a request preprocessor that removes the header named `Foo`.
208
+ <2> Apply a response preprocessor that pretty prints its content.
209
+ ====
0 commit comments