From cb39af5163ce1899129baf479e1f606c3348fe21 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 4 Apr 2016 11:12:15 +0100 Subject: [PATCH] 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 --- .../markdown/default-path-parameters.snippet | 3 ++- .../restdocs/request/PathParametersSnippetTests.java | 12 +++++++++--- .../restdocs/test/SnippetMatchers.java | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/markdown/default-path-parameters.snippet b/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/markdown/default-path-parameters.snippet index f5f1daae..f1811879 100644 --- a/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/markdown/default-path-parameters.snippet +++ b/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/markdown/default-path-parameters.snippet @@ -1,4 +1,5 @@ -{{path}} +`{{path}}` + Parameter | Description --------- | ----------- {{#parameters}} diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java index 7bee0c14..1b50d3d1 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java @@ -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}`"; + } + } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java index a7875b76..bb0c146c 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java @@ -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), " | ");