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.

Documentation on an endpoint with only String as input in RequestBody

See original GitHub issue

Hi,

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:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
davinkevincommented, Mar 11, 2016

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

0reactions
wilkinsonacommented, Mar 21, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

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