question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

responseFields beneathPath does not work with arrays

See original GitHub issue

Using:

org.springframework.restdocs:spring-restdocs-core:2.0.0.RELEASE
org.springframework.restdocs:spring-restdocs-mockmvc:2.0.0.RELEASE

Error:

org.springframework.restdocs.snippet.SnippetException: The following parts of the payload were not documented:
[ {
  "details" : "test details",
  "name" : "testName"
} ]
Fields with the following paths were not found in the payload: [details, name]

Test Code that causes error:

List<FieldDescriptor> responseFieldDescriptors = new ArrayList<>();
responseFieldDescriptors.add(fieldWithPath("details").type(JsonFieldType.STRING).description("Details to display to the customer."));
responseFieldDescriptors.add(fieldWithPath("name").type(JsonFieldType.STRING).description("Customer's name."));


resultActions.andDo(
        MockMvcRestDocumentation.document("content-example",
                preprocessRequest(prettyPrint()),
                preprocessResponse(prettyPrint()),
                responseFields(beneathPath("information.customers[]").withSubsectionId("customer"), responseFieldDescriptors)
        )
);

Test Code that runs but displays unwanted “[].” in generated table

List<FieldDescriptor> responseFieldDescriptors = new ArrayList<>();
responseFieldDescriptors.add(fieldWithPath("[].details").type(JsonFieldType.STRING).description("Details to display to the customer."));
responseFieldDescriptors.add(fieldWithPath("[].name").type(JsonFieldType.STRING).description("Customer's name."));


resultActions.andDo(
        MockMvcRestDocumentation.document("content-example",
                preprocessRequest(prettyPrint()),
                preprocessResponse(prettyPrint()),
                responseFields(beneathPath("information.customers").withSubsectionId("customer"), responseFieldDescriptors)
        )
);

Sample Response:

{
    "information": {
        "customers": [
            "details": "test details",
            "name": "testName"
        ]
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
wilkinsonacommented, May 16, 2018

Ah, I understand now. Yes, in all likelihood the fix will be made in both 1.2.x and 2.0.x although I’ve yet to figure out what the fix should be…

1reaction
wilkinsonacommented, Sep 20, 2018

I’m assuming the open issue means that it still isn’t fixed

Correct.

Is there a workaround so I can make this documentation happen?

I’m not aware of one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

responseFields beneathPath does not work with arrays
Using: org.springframework.restdocs:spring-restdocs-core:2.0.0.RELEASE org.springframework.restdocs:spring-restdocs-mockmvc:2.0.0.RELEASE.
Read more >
How to document a mixed typed array structures in requests ...
It looks like that [0] or [1] does not work and is interpreted as []. ... The beneathPath method that you've tried to...
Read more >
Spring REST Docs
The aim of Spring REST Docs is to help you produce accurate and readable documentation for your RESTful services.
Read more >
ResponseFieldsSnippet.document - Java - Tabnine
expectMessage( equalTo("Cannot document response fields as the response body is empty")); new ResponseFieldsSnippet(Arrays.
Read more >
짜증나는 Restdoc 템플릿을 조금 더 편하게 작성하자
type(NUMBER).description("영화 별점") ), responseFields( beneathPath ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found