Optional path and req param descriptors should count as documented
Previously, optional path and request parameter descriptors were ignored when checking that all of the parameters that are present had been documented. This lead to a false negative if a request or path parameter was present and was documented with an optional descriptor. This commit uses all of the descriptors, not just those that are not optional, when checking for undocumented parameters. Closes gh-228
This commit is contained in:
@@ -124,7 +124,7 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet {
|
||||
}
|
||||
else {
|
||||
undocumentedParameters = new HashSet<>(actualParameters);
|
||||
undocumentedParameters.removeAll(expectedParameters);
|
||||
undocumentedParameters.removeAll(this.descriptorsByName.keySet());
|
||||
}
|
||||
Set<String> missingParameters = new HashSet<>(expectedParameters);
|
||||
missingParameters.removeAll(actualParameters);
|
||||
|
||||
@@ -99,6 +99,24 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
|
||||
"/{a}").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void presentOptionalPathParameter() throws IOException {
|
||||
this.snippet
|
||||
.expectPathParameters(
|
||||
"present-optional-path-parameter")
|
||||
.withContents(tableWithTitleAndHeader(
|
||||
this.templateFormat == TemplateFormats.asciidoctor() ? "/{a}"
|
||||
: "`/{a}`",
|
||||
"Parameter", "Description").row("a", "one"));
|
||||
new PathParametersSnippet(
|
||||
Arrays.asList(parameterWithName("a").description("one").optional()))
|
||||
.document(operationBuilder("present-optional-path-parameter")
|
||||
.attribute(
|
||||
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
|
||||
"/{a}")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathParametersWithQueryString() throws IOException {
|
||||
this.snippet.expectPathParameters("path-parameters-with-query-string")
|
||||
|
||||
@@ -104,6 +104,17 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void presentOptionalRequestParameter() throws IOException {
|
||||
this.snippet.expectRequestParameters("present-optional-request-parameter")
|
||||
.withContents(
|
||||
tableWithHeader("Parameter", "Description").row("a", "one"));
|
||||
new RequestParametersSnippet(
|
||||
Arrays.asList(parameterWithName("a").description("one").optional()))
|
||||
.document(operationBuilder("present-optional-request-parameter")
|
||||
.request("http://localhost").param("a", "one").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestParametersWithCustomAttributes() throws IOException {
|
||||
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
|
||||
|
||||
Reference in New Issue
Block a user