Skip to content

Commit d62ee4f

Browse files
committed
Merge pull request #676 from bric3
* gh-676: Polish "Propagate ignoreUndocumentedParamteres with .and()" Propagate ignoreUndocumentedParamteres with .and() Closes gh-676
2 parents b02fcbe + ffe4c93 commit d62ee4f

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -148,6 +148,16 @@ protected final Map<String, ParameterDescriptor> getParameterDescriptors() {
148148
return this.descriptorsByName;
149149
}
150150

151+
/**
152+
* Returns whether to ignore undocumented parameters.
153+
* @return {@code true} if undocumented parameters should be ignored, otherwise
154+
* {@code false}
155+
* @since 2.0.5
156+
*/
157+
protected final boolean isIgnoreUndocumentedParameters() {
158+
return this.ignoreUndocumentedParameters;
159+
}
160+
151161
/**
152162
* Returns a model for the given {@code descriptor}.
153163
* @param descriptor the descriptor

spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -170,7 +170,7 @@ public final PathParametersSnippet and(ParameterDescriptor... additionalDescript
170170
public final PathParametersSnippet and(List<ParameterDescriptor> additionalDescriptors) {
171171
List<ParameterDescriptor> combinedDescriptors = new ArrayList<>(getParameterDescriptors().values());
172172
combinedDescriptors.addAll(additionalDescriptors);
173-
return new PathParametersSnippet(combinedDescriptors, this.getAttributes());
173+
return new PathParametersSnippet(combinedDescriptors, this.getAttributes(), isIgnoreUndocumentedParameters());
174174
}
175175

176176
}

spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -133,7 +133,8 @@ public RequestParametersSnippet and(ParameterDescriptor... additionalDescriptors
133133
public RequestParametersSnippet and(List<ParameterDescriptor> additionalDescriptors) {
134134
List<ParameterDescriptor> combinedDescriptors = new ArrayList<>(getParameterDescriptors().values());
135135
combinedDescriptors.addAll(additionalDescriptors);
136-
return new RequestParametersSnippet(combinedDescriptors, this.getAttributes());
136+
return new RequestParametersSnippet(combinedDescriptors, this.getAttributes(),
137+
this.isIgnoreUndocumentedParameters());
137138
}
138139

139140
}

spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -159,6 +159,16 @@ public void additionalDescriptors() throws IOException {
159159
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("`a`", "one").row("`b`", "two"));
160160
}
161161

162+
@Test
163+
public void additionalDescriptorsWithRelaxedRequestParameters() throws IOException {
164+
RequestDocumentation.relaxedPathParameters(parameterWithName("a").description("one"))
165+
.and(parameterWithName("b").description("two")).document(this.operationBuilder
166+
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, "/{a}/{b}/{c}").build());
167+
assertThat(this.generatedSnippets.pathParameters())
168+
.is(tableWithTitleAndHeader(getTitle("/{a}/{b}/{c}"), "Parameter", "Description").row("`a`", "one")
169+
.row("`b`", "two"));
170+
}
171+
162172
@Test
163173
public void pathParametersWithEscapedContent() throws IOException {
164174
RequestDocumentation.pathParameters(parameterWithName("Foo|Bar").description("one|two"))

spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -153,6 +153,16 @@ public void additionalDescriptors() throws IOException {
153153
.is(tableWithHeader("Parameter", "Description").row("`a`", "one").row("`b`", "two"));
154154
}
155155

156+
@Test
157+
public void additionalDescriptorsWithRelaxedRequestParameters() throws IOException {
158+
RequestDocumentation.relaxedRequestParameters(parameterWithName("a").description("one"))
159+
.and(parameterWithName("b").description("two"))
160+
.document(this.operationBuilder.request("http://localhost").param("a", "bravo").param("b", "bravo")
161+
.param("c", "undocumented").build());
162+
assertThat(this.generatedSnippets.requestParameters())
163+
.is(tableWithHeader("Parameter", "Description").row("`a`", "one").row("`b`", "two"));
164+
}
165+
156166
@Test
157167
public void requestParametersWithEscapedContent() throws IOException {
158168
RequestDocumentation.requestParameters(parameterWithName("Foo|Bar").description("one|two"))

0 commit comments

Comments
 (0)