當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestParametersSnippet類代碼示例

本文整理匯總了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!");
}
 
開發者ID:ePages-de,項目名稱:restdocs-raml,代碼行數:18,代碼來源:DescriptorExtractorTest.java

示例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]);
}
 
開發者ID:ePages-de,項目名稱:restdocs-raml,代碼行數:61,代碼來源:RamlDocumentation.java


注:本文中的org.springframework.restdocs.request.RequestParametersSnippet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。