Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit ad83b02

Browse files
authored
Snippet configuration documentation (#198)
* snippet configuration documentation * review * docs
1 parent 628d46e commit ad83b02

File tree

6 files changed

+124
-23
lines changed

6 files changed

+124
-23
lines changed

docs/index.html

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ <h1>Spring Auto REST Docs</h1>
467467
<li><a href="#paging">Paging support</a></li>
468468
<li><a href="#preprocessors">Preprocessors</a></li>
469469
<li><a href="#deprecation">Deprecation support</a></li>
470+
<li><a href="#see-tag">See tag support</a></li>
470471
<li><a href="#localization">Localization support</a></li>
471472
</ul>
472473
</li>
@@ -949,6 +950,19 @@ <h3 id="snippets-path-parameters"><a class="link" href="#snippets-path-parameter
949950
</tr>
950951
</tbody>
951952
</table>
953+
<div class="sect3">
954+
<h4 id="_configuration"><a class="link" href="#_configuration">Configuration</a></h4>
955+
<div class="paragraph">
956+
<p>Configuration available during MockMvc setup:</p>
957+
</div>
958+
<div class="ulist">
959+
<ul>
960+
<li>
961+
<p><code>failOnUndocumentedParams</code> - if build should fail on at least one undocumented parameter</p>
962+
</li>
963+
</ul>
964+
</div>
965+
</div>
952966
</div>
953967
<div class="sect2">
954968
<h3 id="snippets-request-parameters"><a class="link" href="#snippets-request-parameters">Request parameters snippet</a></h3>
@@ -1001,6 +1015,19 @@ <h3 id="snippets-request-parameters"><a class="link" href="#snippets-request-par
10011015
</tr>
10021016
</tbody>
10031017
</table>
1018+
<div class="sect3">
1019+
<h4 id="_configuration_2"><a class="link" href="#_configuration_2">Configuration</a></h4>
1020+
<div class="paragraph">
1021+
<p>Configuration available during MockMvc setup:</p>
1022+
</div>
1023+
<div class="ulist">
1024+
<ul>
1025+
<li>
1026+
<p><code>failOnUndocumentedParams</code> - if build should fail on at least one undocumented parameter</p>
1027+
</li>
1028+
</ul>
1029+
</div>
1030+
</div>
10041031
</div>
10051032
<div class="sect2">
10061033
<h3 id="snippets-request-headers"><a class="link" href="#snippets-request-headers">Request headers snippet</a></h3>
@@ -1105,6 +1132,22 @@ <h3 id="snippets-request-fields"><a class="link" href="#snippets-request-fields"
11051132
</tr>
11061133
</tbody>
11071134
</table>
1135+
<div class="sect3">
1136+
<h4 id="_configuration_3"><a class="link" href="#_configuration_3">Configuration</a></h4>
1137+
<div class="paragraph">
1138+
<p>Configuration available during MockMvc setup:</p>
1139+
</div>
1140+
<div class="ulist">
1141+
<ul>
1142+
<li>
1143+
<p><code>failOnUndocumentedFields</code> - if build should fail on at least one undocumented field</p>
1144+
</li>
1145+
<li>
1146+
<p><code>requestBodyAsType</code> - specified class should be considered as request type instead of endpoint method&#8217;s parameter</p>
1147+
</li>
1148+
</ul>
1149+
</div>
1150+
</div>
11081151
</div>
11091152
<div class="sect2">
11101153
<h3 id="snippets-response-fields"><a class="link" href="#snippets-response-fields">Response fields snippet</a></h3>
@@ -1165,6 +1208,22 @@ <h3 id="snippets-response-fields"><a class="link" href="#snippets-response-field
11651208
</tr>
11661209
</tbody>
11671210
</table>
1211+
<div class="sect3">
1212+
<h4 id="_configuration_4"><a class="link" href="#_configuration_4">Configuration</a></h4>
1213+
<div class="paragraph">
1214+
<p>Configuration available during MockMvc setup:</p>
1215+
</div>
1216+
<div class="ulist">
1217+
<ul>
1218+
<li>
1219+
<p><code>failOnUndocumentedFields</code> - if build should fail on at least one undocumented field</p>
1220+
</li>
1221+
<li>
1222+
<p><code>responseBodyAsType</code> - specified class should be considered as response type instead of endpoint method&#8217;s return type</p>
1223+
</li>
1224+
</ul>
1225+
</div>
1226+
</div>
11681227
</div>
11691228
<div class="sect2">
11701229
<h3 id="snippets-section"><a class="link" href="#snippets-section">Section snippet</a></h3>
@@ -1350,7 +1409,7 @@ <h5 id="snippets-section-customization-title"><a class="link" href="#snippets-se
13501409
If missing, it&#8217;s derived from the method name, e.g. <code>getItemById</code> &#8594; <em>Get Item By Id</em>.</p>
13511410
</div>
13521411
<div class="paragraph">
1353-
<p>If you use <code>@title</code> tag and want to generate regular Javadoc we well,
1412+
<p>If you use <code>@title</code> tag and want to generate regular Javadoc as well,
13541413
you need to include this tag among custom tags in plugin configuration.</p>
13551414
</div>
13561415
<div class="listingblock">
@@ -1671,12 +1730,20 @@ <h3 id="deprecation"><a class="link" href="#deprecation">Deprecation support</a>
16711730
</ul>
16721731
</div>
16731732
<div class="paragraph">
1674-
<p>The deprecation is only visible when using <a href="#snippets-section">Section</a> approach. Then it will be shown in the title (also visible in
1675-
TOC) and description. Field&#8217;s deprecation is shown in description column of request/response table.
1733+
<p>Deprecation is shown in the title of an endpoint (also visible in TOC) and description.
1734+
Field&#8217;s deprecation is shown in description column of request/response table.<br>
16761735
See how it looks in the <a href="https://htmlpreview.github.io/?https://github.com/ScaCap/spring-auto-restdocs/blob/master/spring-auto-restdocs-example/generated-docs/index.html#resources-item-resource-test-clone-item">example project</a>.</p>
16771736
</div>
16781737
</div>
16791738
<div class="sect2">
1739+
<h3 id="see-tag"><a class="link" href="#see-tag">See tag support</a></h3>
1740+
<div class="paragraph">
1741+
<p><code>@see</code> Javadoc tag comment will be added to the main description section of an endpoint or a field.<br>
1742+
Currently supports only HTML links. Does not support Java code references.<br>
1743+
See how it looks in the <a href="https://htmlpreview.github.io/?https://github.com/ScaCap/spring-auto-restdocs/blob/master/spring-auto-restdocs-example/generated-docs/index.html#resources-item-resource-test-search">example project</a>.</p>
1744+
</div>
1745+
</div>
1746+
<div class="sect2">
16801747
<h3 id="localization"><a class="link" href="#localization">Localization support</a></h3>
16811748
<div class="paragraph">
16821749
<p>For custom translations of section titles, table headers and other messages:</p>
@@ -1773,7 +1840,7 @@ <h4 id="contributing-building-build"><a class="link" href="#contributing-buildin
17731840
</div>
17741841
<div id="footer">
17751842
<div id="footer-text">
1776-
Last updated 2018-01-06 21:38:23 CET
1843+
Last updated 2018-01-09 13:17:48 CET
17771844
</div>
17781845
</div>
17791846
<link rel="stylesheet" href="highlight/styles/github.min.css">

spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/AutoDocumentation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@ public static JacksonResponseFieldSnippet responseFields() {
4343
return new JacksonResponseFieldSnippet();
4444
}
4545

46-
public static Snippet pathParameters() {
46+
public static PathParametersSnippet pathParameters() {
4747
return new PathParametersSnippet();
4848
}
4949

50-
public static Snippet requestHeaders() {
50+
public static RequestHeaderSnippet requestHeaders() {
5151
return new RequestHeaderSnippet();
5252
}
5353

54-
public static Snippet requestParameters() {
54+
public static RequestParametersSnippet requestParameters() {
5555
return new RequestParametersSnippet();
5656
}
5757

58-
public static Snippet description() {
58+
public static DescriptionSnippet description() {
5959
return new DescriptionSnippet();
6060
}
6161

62-
public static Snippet methodAndPath() {
62+
public static MethodAndPathSnippet methodAndPath() {
6363
return new MethodAndPathSnippet();
6464
}
6565

spring-auto-restdocs-docs/other.adoc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
:example-dir: {master-dir}/spring-auto-restdocs-example
33
:core-package: {master-dir}//spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs
44
:restdocs-package: https://github.com/spring-projects/spring-restdocs/blob/master/spring-restdocs-core/src/main/java/org/springframework/restdocs
5+
:html-preview: https://htmlpreview.github.io/?
56

67
[[other]]
78
== Other
@@ -33,9 +34,16 @@ Endpoint or field will be marked as deprecated if at least one of these is prese
3334
- method / field is annotated with `@Deprecated`
3435
- method's / field's Javadoc has `@deprecated` tag
3536

36-
The deprecation is only visible when using <<snippets-section,Section>> approach. Then it will be shown in the title (also visible in
37-
TOC) and description. Field's deprecation is shown in description column of request/response table.
38-
See how it looks in the link:https://htmlpreview.github.io/?https://github.com/ScaCap/spring-auto-restdocs/blob/master/spring-auto-restdocs-example/generated-docs/index.html#resources-item-resource-test-clone-item[example project].
37+
Deprecation is shown in the title of an endpoint (also visible in TOC) and description.
38+
Field's deprecation is shown in description column of request/response table. +
39+
See how it looks in the link:{html-preview}{example-dir}/generated-docs/index.html#resources-item-resource-test-clone-item[example project].
40+
41+
[[see-tag]]
42+
=== See tag support
43+
44+
`@see` Javadoc tag comment will be added to the main description section of an endpoint or a field. +
45+
Currently supports only HTML links. Does not support Java code references. +
46+
See how it looks in the link:{html-preview}{example-dir}/generated-docs/index.html#resources-item-resource-test-search[example project].
3947

4048
[[localization]]
4149
=== Localization support

spring-auto-restdocs-docs/section-snippet.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ AutoDocumentation.sectionBuilder()
125125
Section title uses text from `@title` Javadoc tag on the handler method.
126126
If missing, it's derived from the method name, e.g. `getItemById` -> _Get Item By Id_.
127127

128-
If you use `@title` tag and want to generate regular Javadoc we well,
128+
If you use `@title` tag and want to generate regular Javadoc as well,
129129
you need to include this tag among custom tags in plugin configuration.
130130

131131
.Custom maven-javadoc-plugin configuration

spring-auto-restdocs-docs/snippets.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ public ItemResponse getItem(@PathVariable String id) { ... }
111111

112112
|===
113113

114+
==== Configuration
115+
116+
Configuration available during MockMvc setup:
117+
118+
- `failOnUndocumentedParams` - if build should fail on at least one undocumented parameter
119+
114120
[[snippets-request-parameters]]
115121
=== Request parameters snippet
116122

@@ -148,6 +154,12 @@ Default value: "en".
148154

149155
|===
150156

157+
==== Configuration
158+
159+
Configuration available during MockMvc setup:
160+
161+
- `failOnUndocumentedParams` - if build should fail on at least one undocumented parameter
162+
151163
[[snippets-request-headers]]
152164
=== Request headers snippet
153165

@@ -223,6 +235,13 @@ Size must be between 0 and 20 inclusive.
223235

224236
|===
225237

238+
==== Configuration
239+
240+
Configuration available during MockMvc setup:
241+
242+
- `failOnUndocumentedFields` - if build should fail on at least one undocumented field
243+
- `requestBodyAsType` - specified class should be considered as request type instead of endpoint method's parameter
244+
226245
[[snippets-response-fields]]
227246
=== Response fields snippet
228247

@@ -268,6 +287,13 @@ Must be at least 1.
268287

269288
|===
270289

290+
==== Configuration
291+
292+
Configuration available during MockMvc setup:
293+
294+
- `failOnUndocumentedFields` - if build should fail on at least one undocumented field
295+
- `responseBodyAsType` - specified class should be considered as response type instead of endpoint method's return type
296+
271297
include::section-snippet.adoc[]
272298

273299
[[snippets-custom]]

spring-auto-restdocs-example/generated-docs/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ <h4 id="_example_request"><a class="anchor" href="#_example_request"></a><a clas
11221122
<div class="content">
11231123
<pre class="highlightjs highlight"><code class="language-bash" data-lang="bash">$ curl 'http://localhost:8080/items' -i -X POST \
11241124
-H 'Content-Type: application/json' \
1125-
-H 'Authorization: Bearer 5594beae-01ec-412b-9169-b69c30696c18' \
1125+
-H 'Authorization: Bearer d6876398-3ace-4051-bf6f-4d21049d3f6d' \
11261126
-d '{"description":"Hot News"}'</code></pre>
11271127
</div>
11281128
</div>
@@ -1359,7 +1359,7 @@ <h4 id="_example_request_2"><a class="anchor" href="#_example_request_2"></a><a
13591359
<div class="content">
13601360
<pre class="highlightjs highlight"><code class="language-bash" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i -X PUT \
13611361
-H 'Content-Type: application/json' \
1362-
-H 'Authorization: Bearer 5594beae-01ec-412b-9169-b69c30696c18' \
1362+
-H 'Authorization: Bearer d6876398-3ace-4051-bf6f-4d21049d3f6d' \
13631363
-d '{"description":"Hot News"}'</code></pre>
13641364
</div>
13651365
</div>
@@ -1465,7 +1465,7 @@ <h4 id="_example_request_3"><a class="anchor" href="#_example_request_3"></a><a
14651465
<div class="listingblock">
14661466
<div class="content">
14671467
<pre class="highlightjs highlight"><code class="language-bash" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i -X DELETE \
1468-
-H 'Authorization: Bearer 5594beae-01ec-412b-9169-b69c30696c18'</code></pre>
1468+
-H 'Authorization: Bearer d6876398-3ace-4051-bf6f-4d21049d3f6d'</code></pre>
14691469
</div>
14701470
</div>
14711471
</div>
@@ -1950,19 +1950,19 @@ <h4 id="_example_response_5"><a class="anchor" href="#_example_response_5"></a><
19501950
"page" : 0,
19511951
"size" : 20,
19521952
"sort" : null,
1953+
"offset" : 0,
19531954
"pageNumber" : 0,
1954-
"pageSize" : 20,
1955-
"offset" : 0
1955+
"pageSize" : 20
19561956
},
19571957
"total" : 1,
19581958
"totalPages" : 1,
1959-
"last" : true,
19601959
"totalElements" : 1,
1960+
"last" : true,
1961+
"size" : 20,
1962+
"number" : 0,
19611963
"sort" : null,
1962-
"first" : true,
19631964
"numberOfElements" : 1,
1964-
"size" : 20,
1965-
"number" : 0
1965+
"first" : true
19661966
}</code></pre>
19671967
</div>
19681968
</div>
@@ -2537,7 +2537,7 @@ <h4 id="_example_request_response_3"><a class="anchor" href="#_example_request_r
25372537
</div>
25382538
<div id="footer">
25392539
<div id="footer-text">
2540-
Last updated 2018-01-06 21:26:54 CET
2540+
Last updated 2018-01-09 13:15:28 CET
25412541
</div>
25422542
</div>
25432543
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/styles/github.min.css">

0 commit comments

Comments
 (0)