本文整理汇总了Java中org.springframework.restdocs.request.RequestParametersSnippet类的典型用法代码示例。如果您正苦于以下问题:Java RequestParametersSnippet类的具体用法?Java RequestParametersSnippet怎么用?Java RequestParametersSnippet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestParametersSnippet类属于org.springframework.restdocs.request包,在下文中一共展示了RequestParametersSnippet类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: should_extract_request_parameter_descriptors
import org.springframework.restdocs.request.RequestParametersSnippet; //导入依赖的package包/类
@Test
public void should_extract_request_parameter_descriptors() {
// given
RequestParametersSnippet snippet = requestParameters(
parameterWithName("page").description("Is documented!"),
parameterWithName("elementsPerPage").description("Is documented!")
);
// when
List<ParameterDescriptor> descriptors = extract(snippet);
then(descriptors).hasSize(2);
then(descriptors.stream().map(ParameterDescriptor::getName).collect(toList()))
.containsExactly("page", "elementsPerPage");
then(descriptors.stream().map(AbstractDescriptor::getDescription).collect(toList()))
.containsExactly("Is documented!", "Is documented!");
}
示例2: enhanceSnippetsWithRaml
import org.springframework.restdocs.request.RequestParametersSnippet; //导入依赖的package包/类
protected static Snippet[] enhanceSnippetsWithRaml(String description,
boolean privateResource,
Function<List<Snippet>, List<Snippet>> snippetFilter,
Snippet... snippets) {
List<RequestFieldsSnippet> requestFieldsSnippets = new ArrayList<>();
List<ResponseFieldsSnippet> responseFieldsSnippets = new ArrayList<>();
List<LinksSnippet> linkSnippets = new ArrayList<>();
List<RequestParametersSnippet> requestParametersSnippets = new ArrayList<>();
List<PathParametersSnippet> pathParametersSnippets = new ArrayList<>();
List<Snippet> ramlSnippets = new ArrayList<>();
List<Snippet> otherSnippets = new ArrayList<>();
for (Snippet snippet : snippets) {
if (snippet instanceof RequestFieldsSnippet) {
requestFieldsSnippets.add((RequestFieldsSnippet) snippet);
} else if (snippet instanceof ResponseFieldsSnippet) {
responseFieldsSnippets.add((ResponseFieldsSnippet) snippet);
} else if (snippet instanceof LinksSnippet) {
linkSnippets.add((LinksSnippet) snippet);
} else if (snippet instanceof RequestParametersSnippet) {
requestParametersSnippets.add((RequestParametersSnippet) snippet);
} else if (snippet instanceof PathParametersSnippet) {
pathParametersSnippets.add((PathParametersSnippet) snippet);
} else if (snippet instanceof RamlResourceSnippet) {
ramlSnippets.add(snippet);
} else {
otherSnippets.add(snippet);
}
}
List<Snippet> enhancedSnippets = new ArrayList<>();
enhancedSnippets.addAll(requestFieldsSnippets);
enhancedSnippets.addAll(responseFieldsSnippets);
enhancedSnippets.addAll(linkSnippets);
enhancedSnippets.addAll(requestParametersSnippets);
enhancedSnippets.addAll(pathParametersSnippets);
enhancedSnippets.addAll(otherSnippets);
if (ramlSnippets.isEmpty()) { // No RamlResourceSnippet, so we configure our own based on the info of the other snippets
RamlResourceSnippetParameters ramlParameters = RamlResourceSnippetParameters.builder()
.description(description)
.privateResource(privateResource)
.requestFields(requestFieldsSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(FieldDescriptor[]::new))
.responseFields(responseFieldsSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(FieldDescriptor[]::new))
.links(linkSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(LinkDescriptor[]::new))
.requestParameters(requestParametersSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(ParameterDescriptor[]::new))
.pathParameters(pathParametersSnippets.stream().map(DescriptorExtractor::extract).flatMap(List::stream).toArray(ParameterDescriptor[]::new))
.build();
enhancedSnippets.add(ramlResource(ramlParameters));
} else {
enhancedSnippets.addAll(ramlSnippets);
}
enhancedSnippets = snippetFilter.apply(enhancedSnippets);
return enhancedSnippets.toArray(new Snippet[0]);
}