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

Commit 431f76e

Browse files
Josef-Reichardtjmisur
authored andcommitted
Improve addDot (#240)
* Improve addDot * Added test for improved addDot * Updated sample application to show improved addDot * Adopted sample docs to comply with project docs * Fixed indentation * Added more unit tests
1 parent 28ae521 commit 431f76e

File tree

5 files changed

+59
-22
lines changed

5 files changed

+59
-22
lines changed

samples/java-webmvc/generated-docs/index.html

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ <h4 id="_response_fields"><a class="anchor" href="#_response_fields"></a><a clas
804804
<h4 id="_example_request_response"><a class="anchor" href="#_example_request_response"></a><a class="link" href="#_example_request_response">2.1.5. Example request/response</a></h4>
805805
<div class="listingblock">
806806
<div class="content">
807-
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i</code></pre>
807+
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i -X GET</code></pre>
808808
</div>
809809
</div>
810810
<div class="listingblock">
@@ -859,6 +859,22 @@ <h3 id="resources-items-all"><a class="anchor" href="#resources-items-all"></a><
859859
<div class="paragraph">
860860
<p>This endpoint really returns all items and that is always 100.</p>
861861
</div>
862+
<div class="paragraph">
863+
<p>Returns list of all items.</p>
864+
</div>
865+
<div class="paragraph">
866+
<p>Use query parameters to filter the list by:</p>
867+
</div>
868+
<div class="ulist">
869+
<ul>
870+
<li>
871+
<p>orderNumber</p>
872+
</li>
873+
<li>
874+
<p>type</p>
875+
</li>
876+
</ul>
877+
</div>
862878
<div class="sect3">
863879
<h4 id="_authorization_2"><a class="anchor" href="#_authorization_2"></a><a class="link" href="#_authorization_2">2.2.1. Authorization</a></h4>
864880
<div class="paragraph">
@@ -994,7 +1010,7 @@ <h4 id="_response_fields_2"><a class="anchor" href="#_response_fields_2"></a><a
9941010
<h4 id="_example_request_response_2"><a class="anchor" href="#_example_request_response_2"></a><a class="link" href="#_example_request_response_2">2.2.4. Example request/response</a></h4>
9951011
<div class="listingblock">
9961012
<div class="content">
997-
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items' -i</code></pre>
1013+
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items' -i -X GET</code></pre>
9981014
</div>
9991015
</div>
10001016
<div class="paragraph">
@@ -1129,7 +1145,7 @@ <h4 id="_example_request"><a class="anchor" href="#_example_request"></a><a clas
11291145
<div class="content">
11301146
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items' -i -X POST \
11311147
-H 'Content-Type: application/json' \
1132-
-H 'Authorization: Bearer 23d918a4-653f-4e61-9b46-b5e72fd2ba7c' \
1148+
-H 'Authorization: Bearer 55ad9296-b11a-4713-8370-a6c617d9656a' \
11331149
-d '{"description":"Hot News"}'</code></pre>
11341150
</div>
11351151
</div>
@@ -1366,7 +1382,7 @@ <h4 id="_example_request_2"><a class="anchor" href="#_example_request_2"></a><a
13661382
<div class="content">
13671383
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i -X PUT \
13681384
-H 'Content-Type: application/json' \
1369-
-H 'Authorization: Bearer 23d918a4-653f-4e61-9b46-b5e72fd2ba7c' \
1385+
-H 'Authorization: Bearer 55ad9296-b11a-4713-8370-a6c617d9656a' \
13701386
-d '{"description":"Hot News"}'</code></pre>
13711387
</div>
13721388
</div>
@@ -1472,7 +1488,7 @@ <h4 id="_example_request_3"><a class="anchor" href="#_example_request_3"></a><a
14721488
<div class="listingblock">
14731489
<div class="content">
14741490
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i -X DELETE \
1475-
-H 'Authorization: Bearer 23d918a4-653f-4e61-9b46-b5e72fd2ba7c'</code></pre>
1491+
-H 'Authorization: Bearer 55ad9296-b11a-4713-8370-a6c617d9656a'</code></pre>
14761492
</div>
14771493
</div>
14781494
</div>
@@ -1682,7 +1698,7 @@ <h4 id="_response_fields_6"><a class="anchor" href="#_response_fields_6"></a><a
16821698
<h4 id="_example_request_4"><a class="anchor" href="#_example_request_4"></a><a class="link" href="#_example_request_4">2.6.6. Example request</a></h4>
16831699
<div class="listingblock">
16841700
<div class="content">
1685-
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1/child-1' -i</code></pre>
1701+
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1/child-1' -i -X GET</code></pre>
16861702
</div>
16871703
</div>
16881704
</div>
@@ -1909,7 +1925,7 @@ <h4 id="_response_fields_7"><a class="anchor" href="#_response_fields_7"></a><a
19091925
<h4 id="_example_request_5"><a class="anchor" href="#_example_request_5"></a><a class="link" href="#_example_request_5">2.7.6. Example request</a></h4>
19101926
<div class="listingblock">
19111927
<div class="content">
1912-
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/search?desc=main&amp;hint=1' -i</code></pre>
1928+
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/search?desc=main&amp;hint=1' -i -X GET</code></pre>
19131929
</div>
19141930
</div>
19151931
</div>
@@ -1961,25 +1977,25 @@ <h4 id="_example_response_5"><a class="anchor" href="#_example_response_5"></a><
19611977
"sorted" : false,
19621978
"unsorted" : true
19631979
},
1964-
"offset" : 0,
19651980
"pageSize" : 20,
19661981
"pageNumber" : 0,
1982+
"offset" : 0,
19671983
"paged" : true,
19681984
"unpaged" : false
19691985
},
19701986
"total" : 1,
1971-
"totalElements" : 1,
19721987
"totalPages" : 1,
1988+
"totalElements" : 1,
19731989
"last" : true,
1974-
"size" : 20,
1975-
"number" : 0,
1976-
"numberOfElements" : 1,
1990+
"first" : true,
19771991
"sort" : {
19781992
"orders" : [ ],
19791993
"sorted" : false,
19801994
"unsorted" : true
19811995
},
1982-
"first" : true
1996+
"numberOfElements" : 1,
1997+
"size" : 20,
1998+
"number" : 0
19831999
}</code></pre>
19842000
</div>
19852001
</div>
@@ -2471,7 +2487,7 @@ <h4 id="_path_parameters_11"><a class="anchor" href="#_path_parameters_11"></a><
24712487
</thead>
24722488
<tbody>
24732489
<tr>
2474-
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>id</code></p></td>
2490+
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>+id+</code></p></td>
24752491
<td class="tableblock halign-left valign-top"><p class="tableblock">ID of the item.</p></td>
24762492
</tr>
24772493
</tbody>
@@ -2494,8 +2510,8 @@ <h4 id="_response_fields_12"><a class="anchor" href="#_response_fields_12"></a><
24942510
</thead>
24952511
<tbody>
24962512
<tr>
2497-
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>id</code></p></td>
2498-
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
2513+
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>+id+</code></p></td>
2514+
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>+String+</code></p></td>
24992515
<td class="tableblock halign-left valign-top"><p class="tableblock">There are more fields but only the ID field is documented.</p></td>
25002516
</tr>
25012517
</tbody>
@@ -2505,7 +2521,7 @@ <h4 id="_response_fields_12"><a class="anchor" href="#_response_fields_12"></a><
25052521
<h4 id="_example_request_response_3"><a class="anchor" href="#_example_request_response_3"></a><a class="link" href="#_example_request_response_3">2.12.4. Example request/response</a></h4>
25062522
<div class="listingblock">
25072523
<div class="content">
2508-
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i</code></pre>
2524+
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl 'http://localhost:8080/items/1' -i -X GET</code></pre>
25092525
</div>
25102526
</div>
25112527
<div class="listingblock">
@@ -2554,11 +2570,11 @@ <h4 id="_example_request_response_3"><a class="anchor" href="#_example_request_r
25542570
</div>
25552571
<div id="footer">
25562572
<div id="footer-text">
2557-
Last updated 2018-03-29 11:51:15 CEST
2573+
Last updated 2018-06-15 10:19:16 MESZ
25582574
</div>
25592575
</div>
25602576
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
25612577
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
25622578
<script>hljs.initHighlighting()</script>
25632579
</body>
2564-
</html>
2580+
</html>

samples/java-webmvc/src/main/asciidoc/items.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ As AsciiDoc is used, any additional information can be placed here and you don't
4040

4141
This endpoint really returns all items and that is always 100.
4242

43+
include::{snippets}/item-resource-test/get-all-items/auto-description.adoc[]
44+
4345
==== Authorization
4446

4547
include::{snippets}/item-resource-test/get-all-items/auto-authorization.adoc[]

samples/java-webmvc/src/main/java/capital/scalable/restdocs/example/items/ItemResource.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ public ItemResponse getItem(@PathVariable("id") @Id String id) {
9292
}
9393

9494
/**
95-
* Lists all items.
95+
* Returns list of all items.
9696
* <p>
97-
* An example of retuning an array/collection.
97+
* Use query parameters to filter the list by:
98+
* <ul>
99+
* <li>orderNumber</li>
100+
* <li>type</li>
101+
* </ul>
98102
*
99103
* @return list of all items
100104
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static String collectionToString(Collection<?> c) {
3939
}
4040

4141
public static String addDot(String text) {
42-
return isNotBlank(text) && !text.endsWith(".") && !text.endsWith(" ")
42+
return isNotBlank(text) && !text.matches("^(?s).*(?:[.?!:;)\"]|</(?:p|ul|ol)>)\\s*$") && !text.endsWith(" ")
4343
? text + "."
4444
: text;
4545
}

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/util/FormatUtilTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ public void addDot() {
4444
assertThat(FormatUtil.addDot("."), is("."));
4545
assertThat(FormatUtil.addDot("text."), is("text."));
4646
assertThat(FormatUtil.addDot("text"), is("text."));
47+
assertThat(FormatUtil.addDot("text?"), is("text?"));
48+
assertThat(FormatUtil.addDot("text!"), is("text!"));
49+
assertThat(FormatUtil.addDot("text:"), is("text:"));
50+
assertThat(FormatUtil.addDot("text;"), is("text;"));
51+
assertThat(FormatUtil.addDot("text)"), is("text)"));
52+
assertThat(FormatUtil.addDot("text\""), is("text\""));
53+
assertThat(FormatUtil.addDot("text+"), is("text+."));
54+
assertThat(FormatUtil.addDot("text with html:\n<ul>\n<li>first</li>\n<li>second</li>\n</ul>"),
55+
is("text with html:\n<ul>\n<li>first</li>\n<li>second</li>\n</ul>"));
56+
assertThat(FormatUtil.addDot("text with html:\r\n<ul>\r\n<li>first</li>\r\n<li>second</li>\r\n</ul>"),
57+
is("text with html:\r\n<ul>\r\n<li>first</li>\r\n<li>second</li>\r\n</ul>"));
58+
assertThat(FormatUtil.addDot("text with html:\r\n<ol>\r\n<li>first</li>\r\n<li>second</li>\r\n</ol>"),
59+
is("text with html:\r\n<ol>\r\n<li>first</li>\r\n<li>second</li>\r\n</ol>"));
60+
assertThat(FormatUtil.addDot("text with html:\r\n<p>another paragraph</p>"),
61+
is("text with html:\r\n<p>another paragraph</p>"));
4762
}
4863

4964
@Test

0 commit comments

Comments
 (0)