From 145746d753ea103a5611a9b925c30754a3c65816 Mon Sep 17 00:00:00 2001 From: chuuminggg Date: Fri, 16 Oct 2026 14:19:22 +0900 Subject: [PATCH] Remove leading * from the names of capturing path variables Previously, the name of a path variable that captures the rest of the path, such as {*path}, was determined to be *path rather than path. Signed-off-by: chuuminggg See gh-1079 --- .../restdocs/request/PathParametersSnippet.java | 3 ++- .../request/PathParametersSnippetTests.java | 13 +++++++++++++ 2 files changed, 15 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 42178a426..9a40b4629 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 @@ -120,7 +120,8 @@ private String extractUrlTemplate(Operation operation) { private static String getParameterName(String match) { int colonIndex = match.indexOf(':'); - return (colonIndex != -1) ? match.substring(0, colonIndex) : match; + String name = (colonIndex != -1) ? match.substring(0, colonIndex) : match; + return name.startsWith("*") ? name.substring(1) : name; } @Override 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 131468f4b..d2c6ef404 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 @@ -170,6 +170,19 @@ void additionalDescriptorsWithRelaxedRequestParameters(OperationBuilder operatio .row("`b`", "two")); } + @RenderedSnippetTest + void pathParametersWithCaptureVariable(OperationBuilder operationBuilder, AssertableSnippets snippets, + TemplateFormat templateFormat) throws IOException { + new PathParametersSnippet( + Arrays.asList(parameterWithName("a").description("one"), parameterWithName("b").description("two"))) + .document(operationBuilder.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/{a}/{*b}") + .build()); + assertThat(snippets.pathParameters()).isTable( + (table) -> table.withTitleAndHeader(getTitle(templateFormat, "/{a}/{*b}"), "Parameter", "Description") + .row("`a`", "one") + .row("`b`", "two")); + } + @RenderedSnippetTest void pathParametersWithEscapedContent(OperationBuilder operationBuilder, AssertableSnippets snippets, TemplateFormat templateFormat) throws IOException {