Repository: spring-projects/spring-restdocs

Issue #466: Formatting is lost when extracting a subsection from a request or response payload
Created: 2017-12-11T11:42:19Z

Duplicate issue #558: PrettyPrinting when documenting subsection using beneathPath not working
Created: 2018-10-18T19:23:38Z
SpringBoot 2.0.6
restdocs 2.0.2
Given setup of:
this.documentationHandler = document("{method-name}");
       this.documentationHandler = document("{method-name}",
               preprocessRequest(prettyPrint(), removeHeaders("Host", "Content-Length")),
               preprocessResponse(prettyPrint(), removeHeaders("Content-Length")));
       
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
       .apply(documentationConfiguration(this.restDocumentation)
               .operationPreprocessors().withResponseDefaults(prettyPrint()).and()
               .templateEngine(templateEngine)
               .snippets().withDefaults(
                       httpRequest(),
                       httpResponse(),
                       httpRequest(),
                       new RequestBodySnippet(),
                       AutoDocumentation.requestFields(),
                       AutoDocumentation.requestHeaders(),
                       AutoDocumentation.responseFields(),
                       AutoDocumentation.pathParameters(),
                       AutoDocumentation.requestParameters(),
                       AutoDocumentation.description(),
                       AutoDocumentation.methodAndPath(),
                       //AutoDocumentation.section() // use builder to customize which and ordering
                       AutoDocumentation.sectionBuilder()
                           .snippetNames(
                                   SnippetRegistry.REQUEST_HEADERS,
                                   SnippetRegistry.PATH_PARAMETERS,
                                   SnippetRegistry.REQUEST_PARAMETERS,
                                   SnippetRegistry.REQUEST_FIELDS,
                                   SnippetRegistry.HTTP_REQUEST,
                                   SnippetRegistry.RESPONSE_FIELDS,
                                   SnippetRegistry.HTTP_RESPONSE
                           ).skipEmpty(true).build()
               )
       )
       .alwaysDo(JacksonResultHandlers.prepareJackson(objectMapper))
       .alwaysDo(this.documentationHandler)
       .build();

my response-body.adoc and http-response.adocs are pretty printed as expected but the beneathPath.adocs are NOT pretty printed when I document as in:
this.mockMvc
    .perform(RestDocumentationRequestBuilders.get("/api/deliverable/{id}/trackable", "1")
            .accept(MediaType.APPLICATION_JSON)
            .contentType(MediaType.APPLICATION_JSON)
            .header("X-AUTH-TOKEN", "some-jwt-token")
    )
    .andExpect(status().isOk())
    .andDo(documentationHandler.document(
            responseBody(beneathPath("trackable.providerMetadata")),
            responseBody()
            )
    );

Notice I have asked for pretty print in both the  documentationConfiguration and the documentationHandler.
It doesnt seem to matter which approach I use to config for pretty printing (or even using both), only http-response.adoc and response-body.adoc are pretty printed.  The beneath.adocs never are.
As a sanity check, I verified that If none are set, then no adocs are pretty printed, as expected.

Closing comment (2018-10-18T19:33:38Z): Thanks for the report. This is a duplicate of #466.