Skip to content

Commit cb39af5

Browse files
committed
Improve the formatting of the default Markdown path parameters snippet
Add the required blank line between the table "title" and the table itself. Without this blank line the table wasn't not formatted correctly. The "title" has also been wrapped in back ticks to improve its formatting in the generated HTML. Closes gh-212
1 parent 488d36d commit cb39af5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/markdown/default-path-parameters.snippet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{path}}
1+
`{{path}}`
2+
23
Parameter | Description
34
--------- | -----------
45
{{#parameters}}

spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.restdocs.generate.RestDocumentationGenerator;
2626
import org.springframework.restdocs.templates.TemplateEngine;
2727
import org.springframework.restdocs.templates.TemplateFormat;
28+
import org.springframework.restdocs.templates.TemplateFormats;
2829
import org.springframework.restdocs.templates.TemplateResourceResolver;
2930
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
3031

@@ -49,7 +50,7 @@ public PathParametersSnippetTests(String name, TemplateFormat templateFormat) {
4950
@Test
5051
public void pathParameters() throws IOException {
5152
this.snippet.expectPathParameters("path-parameters").withContents(
52-
tableWithTitleAndHeader("/{a}/{b}", "Parameter", "Description")
53+
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
5354
.row("a", "one").row("b", "two"));
5455
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
5556
parameterWithName("b").description("two")))
@@ -61,7 +62,7 @@ public void pathParameters() throws IOException {
6162
@Test
6263
public void ignoredPathParameter() throws IOException {
6364
this.snippet.expectPathParameters("ignored-path-parameter").withContents(
64-
tableWithTitleAndHeader("/{a}/{b}", "Parameter", "Description").row("b",
65+
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("b",
6566
"two"));
6667
new PathParametersSnippet(Arrays.asList(parameterWithName("a").ignored(),
6768
parameterWithName("b").description("two")))
@@ -74,7 +75,7 @@ public void ignoredPathParameter() throws IOException {
7475
public void pathParametersWithQueryString() throws IOException {
7576
this.snippet.expectPathParameters("path-parameters-with-query-string")
7677
.withContents(
77-
tableWithTitleAndHeader("/{a}/{b}", "Parameter", "Description")
78+
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
7879
.row("a", "one").row("b", "two"));
7980
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
8081
parameterWithName("b").description("two"))).document(
@@ -132,4 +133,9 @@ public void pathParametersWithCustomDescriptorAttributes() throws IOException {
132133
.build());
133134
}
134135

136+
private String getTitle() {
137+
return this.templateFormat == TemplateFormats.asciidoctor() ? "/{a}/{b}"
138+
: "`/{a}/{b}`";
139+
}
140+
135141
}

spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ private MarkdownTableMatcher(String title, String... columns) {
345345
super(TemplateFormats.asciidoctor());
346346
if (StringUtils.hasText(title)) {
347347
this.addLine(title);
348+
this.addLine("");
348349
}
349350
String header = StringUtils
350351
.collectionToDelimitedString(Arrays.asList(columns), " | ");

0 commit comments

Comments
 (0)