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

Commit 9a7fa04

Browse files
authored
fixed pipe escaping in tables (#160)
1 parent b0b2242 commit 9a7fa04

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private String joinAndFormat(String description, List<String> constraints,
140140

141141
res.append(constr.toString());
142142

143-
return res.toString();
143+
return res.toString().replace("|", "\\|");
144144
}
145145

146146
private StringBuilder formatConstraints(List<String> constraints, String forcedLineBreak) {

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/payload/JacksonResponseFieldSnippetTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,23 @@ public void failOnUndocumentedFields() throws Exception {
230230
.build());
231231
}
232232

233+
@Test
234+
public void escaping() throws Exception {
235+
HandlerMethod handlerMethod = createHandlerMethod("processItem");
236+
mockFieldComment(ProcessingResponse.class, "output", "An output | result");
233237

238+
this.snippets.expect(RESPONSE_FIELDS).withContents(
239+
tableWithHeader("Path", "Type", "Optional", "Description")
240+
.row("output", "String", "true", "An output \\| result."));
241+
242+
new JacksonResponseFieldSnippet().responseBodyAsType(ProcessingResponse.class)
243+
.document(operationBuilder
244+
.attribute(HandlerMethod.class.getName(), handlerMethod)
245+
.attribute(ObjectMapper.class.getName(), mapper)
246+
.attribute(JavadocReader.class.getName(), javadocReader)
247+
.attribute(ConstraintReader.class.getName(), constraintReader)
248+
.build());
249+
}
234250
private void mockConstraintMessage(Class<?> type, String fieldName, String comment) {
235251
when(constraintReader.getConstraintMessages(type, fieldName))
236252
.thenReturn(singletonList(comment));

spring-auto-restdocs-example/src/main/java/capital/scalable/restdocs/example/items/ItemResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ItemResponse {
7070
private List<ItemResponse> children;
7171

7272
/**
73-
* Some information about the item.
73+
* Some information | description about the item.
7474
*/
7575
public String getDescription() {
7676
return desc;

0 commit comments

Comments
 (0)