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
This commit is contained in:
Andy Wilkinson
2016-04-04 11:12:15 +01:00
parent 488d36d4bf
commit cb39af5163
3 changed files with 12 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
{{path}}
`{{path}}`
Parameter | Description
--------- | -----------
{{#parameters}}

View File

@@ -25,6 +25,7 @@ import org.springframework.restdocs.AbstractSnippetTests;
import org.springframework.restdocs.generate.RestDocumentationGenerator;
import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateFormat;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
@@ -49,7 +50,7 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
@Test
public void pathParameters() throws IOException {
this.snippet.expectPathParameters("path-parameters").withContents(
tableWithTitleAndHeader("/{a}/{b}", "Parameter", "Description")
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("a", "one").row("b", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two")))
@@ -61,7 +62,7 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
@Test
public void ignoredPathParameter() throws IOException {
this.snippet.expectPathParameters("ignored-path-parameter").withContents(
tableWithTitleAndHeader("/{a}/{b}", "Parameter", "Description").row("b",
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("b",
"two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").ignored(),
parameterWithName("b").description("two")))
@@ -74,7 +75,7 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
public void pathParametersWithQueryString() throws IOException {
this.snippet.expectPathParameters("path-parameters-with-query-string")
.withContents(
tableWithTitleAndHeader("/{a}/{b}", "Parameter", "Description")
tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("a", "one").row("b", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two"))).document(
@@ -132,4 +133,9 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
.build());
}
private String getTitle() {
return this.templateFormat == TemplateFormats.asciidoctor() ? "/{a}/{b}"
: "`/{a}/{b}`";
}
}

View File

@@ -345,6 +345,7 @@ public final class SnippetMatchers {
super(TemplateFormats.asciidoctor());
if (StringUtils.hasText(title)) {
this.addLine(title);
this.addLine("");
}
String header = StringUtils
.collectionToDelimitedString(Arrays.asList(columns), " | ");