From a0faebdb0a33f2ccede8c1293a778d78ddccd7fb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 19 Aug 2016 19:51:16 +0100 Subject: [PATCH] Ignore query string when extracting path parameters Closes gh-285 --- .../restdocs/request/PathParametersSnippet.java | 2 +- .../request/PathParametersSnippetTests.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java index afbd0b52..64df77ec 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java @@ -116,7 +116,7 @@ public class PathParametersSnippet extends AbstractParametersSnippet { @Override protected Set extractActualParameters(Operation operation) { - String urlTemplate = extractUrlTemplate(operation); + String urlTemplate = removeQueryStringIfPresent(extractUrlTemplate(operation)); Matcher matcher = NAMES_PATTERN.matcher(urlTemplate); Set actualParameters = new HashSet<>(); while (matcher.find()) { 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 e0980991..fbc7449b 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 @@ -130,6 +130,23 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { "/{a}/{b}?foo=bar").build()); } + @Test + public void pathParametersWithQueryStringWithParameters() throws IOException { + this.snippet + .expectPathParameters("path-parameters-with-query-string-with-parameters") + .withContents( + tableWithTitleAndHeader(getTitle(), "Parameter", "Description") + .row("`a`", "one").row("`b`", "two")); + new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"), + parameterWithName("b").description("two"))) + .document(operationBuilder( + "path-parameters-with-query-string-with-parameters") + .attribute( + RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}?foo={c}") + .build()); + } + @Test public void pathParametersWithCustomAttributes() throws IOException { TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);