Skip to content

Commit ffe4c93

Browse files
committed
Polish "Propagate ignoreUndocumentedParamteres with .and()"
See gh-676
1 parent eac7d67 commit ffe4c93

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

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

+8-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.
@@ -148,8 +148,14 @@ 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+
*/
151157
protected final boolean isIgnoreUndocumentedParameters() {
152-
return ignoreUndocumentedParameters;
158+
return this.ignoreUndocumentedParameters;
153159
}
154160

155161
/**

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(), this.isIgnoreUndocumentedParameters());
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

+4-3
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.
@@ -156,8 +156,9 @@ public void additionalDescriptors() throws IOException {
156156
@Test
157157
public void additionalDescriptorsWithRelaxedRequestParameters() throws IOException {
158158
RequestDocumentation.relaxedRequestParameters(parameterWithName("a").description("one"))
159-
.and(parameterWithName("b").description("two")).document(this.operationBuilder
160-
.request("http://localhost").param("a", "bravo").param("b", "bravo").param("c", "undocumented").build());
159+
.and(parameterWithName("b").description("two"))
160+
.document(this.operationBuilder.request("http://localhost").param("a", "bravo").param("b", "bravo")
161+
.param("c", "undocumented").build());
161162
assertThat(this.generatedSnippets.requestParameters())
162163
.is(tableWithHeader("Parameter", "Description").row("`a`", "one").row("`b`", "two"));
163164
}

0 commit comments

Comments
 (0)