From e14bda08931aaae7b71e158469a2aea43152d3a0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 16 Jul 2018 10:30:14 +0100 Subject: [PATCH] Disable interpolation of Asciidoctor path parameter table's title Previously, when generating Asciidoctor snipppets, the title of the path parameter table was interpolated. The title of the table is the path including its parameters. The parameters are typically surrounded by { and }. This is the same syntax used for attributes in Asciidoctor. With interpolation enabled this caused Asciidoctor to interpret the parameter as an attribute reference and attempt to replace it. This would either result in unwanted replacement of the parameter with the value of the attribute or it would result in a warning about a missing attribute. This commit surrounds the title of the table with + characters. This disables all interpolation for the title, thereby preventing unwanted replacement or attempted replacement of the path's parameters. Closes gh-527 --- .../default-path-parameters.snippet | 2 +- .../request/PathParametersSnippetTests.java | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/asciidoctor/default-path-parameters.snippet b/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/asciidoctor/default-path-parameters.snippet index 0c77a4c1..6976b7b2 100644 --- a/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/asciidoctor/default-path-parameters.snippet +++ b/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/asciidoctor/default-path-parameters.snippet @@ -1,4 +1,4 @@ -.{{path}} +.+{{path}}+ |=== |Parameter|Description 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 9a07feba..e053430d 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 @@ -85,9 +85,11 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { @Test public void missingOptionalPathParameter() throws IOException { - this.snippets.expectPathParameters().withContents(tableWithTitleAndHeader( - this.templateFormat == TemplateFormats.asciidoctor() ? "/{a}" : "`/{a}`", - "Parameter", "Description").row("`a`", "one").row("`b`", "two")); + this.snippets.expectPathParameters() + .withContents(tableWithTitleAndHeader( + this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+" + : "`/{a}`", + "Parameter", "Description").row("`a`", "one").row("`b`", "two")); new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"), parameterWithName("b").description("two").optional())) .document(this.operationBuilder.attribute( @@ -97,9 +99,11 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { @Test public void presentOptionalPathParameter() throws IOException { - this.snippets.expectPathParameters().withContents(tableWithTitleAndHeader( - this.templateFormat == TemplateFormats.asciidoctor() ? "/{a}" : "`/{a}`", - "Parameter", "Description").row("`a`", "one")); + this.snippets.expectPathParameters() + .withContents(tableWithTitleAndHeader( + this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+" + : "`/{a}`", + "Parameter", "Description").row("`a`", "one")); new PathParametersSnippet( Arrays.asList(parameterWithName("a").description("one").optional())) .document(this.operationBuilder.attribute( @@ -216,7 +220,7 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { private String getTitle(String title) { if (this.templateFormat.equals(TemplateFormats.asciidoctor())) { - return title; + return "+" + title + "+"; } return "`" + title + "`"; }