responseFields beneathPath does not work with arrays
See original GitHub issueUsing:
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:
- Created 6 years ago
- Comments:22 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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…
Correct.
I’m not aware of one.