Polish "Propagate ignoreUndocumentedParamteres with .and()"

See gh-676
This commit is contained in:
Andy Wilkinson
2020-09-01 13:54:39 +01:00
parent eac7d67c4e
commit ffe4c93c38
5 changed files with 28 additions and 10 deletions

View File

@@ -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,8 +148,14 @@ 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 ignoreUndocumentedParameters;
return this.ignoreUndocumentedParameters;
}
/**

View File

@@ -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<ParameterDescriptor> additionalDescriptors) {
List<ParameterDescriptor> combinedDescriptors = new ArrayList<>(getParameterDescriptors().values());
combinedDescriptors.addAll(additionalDescriptors);
return new PathParametersSnippet(combinedDescriptors, this.getAttributes());
return new PathParametersSnippet(combinedDescriptors, this.getAttributes(), isIgnoreUndocumentedParameters());
}
}

View File

@@ -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<ParameterDescriptor> additionalDescriptors) {
List<ParameterDescriptor> combinedDescriptors = new ArrayList<>(getParameterDescriptors().values());
combinedDescriptors.addAll(additionalDescriptors);
return new RequestParametersSnippet(combinedDescriptors, this.getAttributes(), this.isIgnoreUndocumentedParameters());
return new RequestParametersSnippet(combinedDescriptors, this.getAttributes(),
this.isIgnoreUndocumentedParameters());
}
}

View File

@@ -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"))

View File

@@ -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.
@@ -156,8 +156,9 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
@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());
.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"));
}