Documentation on an endpoint with only String as input in RequestBody
See original GitHub issueHi,
I try to document something like this :
@RequestMapping(value = "exists", method = RequestMethod.POST, consumes = "text/plain")
public void alreadyExist(@PathVariable UUID id, @RequestBody String email, HttpServletResponse response) {
...
}
and I’ve write this kind of simple test :
@Test
public void should_verify_a_user_doesnt_exist_in_sub() throws Exception {
String email = "foo.bar@mail.com";
this.mockMvc
.perform(
post("/api/v1/subscriptions/{id}/users/exists", "0058d39f-daac-01d7-71a4-edbdcea7c480")
.contentType(MediaType.TEXT_PLAIN_VALUE)
.accept(MediaType.ALL_VALUE)
.content(email)
.andExpect(status().isNoContent())
.andDo(document("api/v1/subscriptions/id/users/exists/post", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
pathParameters(
parameterWithName("id").description("UUID of the subscription")
)
));
}
All is ok, but I don’t find anyway to document the payload of the request. All the method to do that (Payload Documentation) is for working on an object which can be handle by Jackson, and in this case, a String is not a parseable element.
Do I misunderstand something or is it impossible to do that ?
Thanks for your help
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Spring @RequestBody - binding method parameters to ...
The application binds request body parameters of a form POST and JSON post request to mapped method arguments. ... This is the project...
Read more >Get HTTP POST Body in Spring Boot with @RequestBody
This takes the body of the request and neatly packs it into our fullName String. We've then returned this name back, with a...
Read more >Step 3: Parameters (API reference tutorial)
The request body is usually only used with CREATE or PUT methods and ... the header parameters aren't usually documented with each endpoint....
Read more >Describing Request Body - Swagger
Request bodies are typically used with “create” and “update” operations (POST, PUT, PATCH). For example, when creating a resource using POST or PUT,...
Read more >Accepting Raw Request Body Content in ASP.NET Core API ...
Lets start with a non-raw request, but rather with posting a string as JSON since that is very common. You can accept a...
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
Having the same way of generating snippet with primitive and JSON / XML could be better I think. It could generate a single line table with location (obviously, root of RequestBody), Type and Description.
And, if that is possible, if in the future the input type of the controller change (for a JSON Object for example), the RestDoc will throw a error because the object is not correctly documented.
Right now, I’ve documented directly in the Asciidoctor source, but I think it isn’t a consistent way of documenting the API, this is why I open an issue.
Thanks for your help
Thanks for the follow up. Sounds like this discussion has run its course. We can reopen the issue if that proves not to be the case.