diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java index 3be05028..523d65c8 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -148,6 +148,16 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet { return this.descriptorsByName; } + /** + * Returns whether to ignore undocumented parameters. + * @return {@code true} if undocumented parameters should be ignored, otherwise + * {@code false} + * @since 2.0.5 + */ + protected final boolean isIgnoreUndocumentedParameters() { + return this.ignoreUndocumentedParameters; + } + /** * Returns a model for the given {@code descriptor}. * @param descriptor the descriptor 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 91acf47b..6b4f4f32 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 @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -170,7 +170,7 @@ public class PathParametersSnippet extends AbstractParametersSnippet { public final PathParametersSnippet and(List additionalDescriptors) { List combinedDescriptors = new ArrayList<>(getParameterDescriptors().values()); combinedDescriptors.addAll(additionalDescriptors); - return new PathParametersSnippet(combinedDescriptors, this.getAttributes()); + return new PathParametersSnippet(combinedDescriptors, this.getAttributes(), isIgnoreUndocumentedParameters()); } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java index 790a7109..b1a1afc1 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -133,7 +133,8 @@ public class RequestParametersSnippet extends AbstractParametersSnippet { public RequestParametersSnippet and(List additionalDescriptors) { List combinedDescriptors = new ArrayList<>(getParameterDescriptors().values()); combinedDescriptors.addAll(additionalDescriptors); - return new RequestParametersSnippet(combinedDescriptors, this.getAttributes()); + return new RequestParametersSnippet(combinedDescriptors, this.getAttributes(), + this.isIgnoreUndocumentedParameters()); } } 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 2f4b5bdc..bb455ae9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -159,6 +159,16 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("`a`", "one").row("`b`", "two")); } + @Test + public void additionalDescriptorsWithRelaxedRequestParameters() throws IOException { + RequestDocumentation.relaxedPathParameters(parameterWithName("a").description("one")) + .and(parameterWithName("b").description("two")).document(this.operationBuilder + .attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/{a}/{b}/{c}").build()); + assertThat(this.generatedSnippets.pathParameters()) + .is(tableWithTitleAndHeader(getTitle("/{a}/{b}/{c}"), "Parameter", "Description").row("`a`", "one") + .row("`b`", "two")); + } + @Test public void pathParametersWithEscapedContent() throws IOException { RequestDocumentation.pathParameters(parameterWithName("Foo|Bar").description("one|two")) diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java index 85fb1c23..92857a27 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,6 +153,16 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests { .is(tableWithHeader("Parameter", "Description").row("`a`", "one").row("`b`", "two")); } + @Test + public void additionalDescriptorsWithRelaxedRequestParameters() throws IOException { + RequestDocumentation.relaxedRequestParameters(parameterWithName("a").description("one")) + .and(parameterWithName("b").description("two")) + .document(this.operationBuilder.request("http://localhost").param("a", "bravo").param("b", "bravo") + .param("c", "undocumented").build()); + assertThat(this.generatedSnippets.requestParameters()) + .is(tableWithHeader("Parameter", "Description").row("`a`", "one").row("`b`", "two")); + } + @Test public void requestParametersWithEscapedContent() throws IOException { RequestDocumentation.requestParameters(parameterWithName("Foo|Bar").description("one|two"))