-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request body is empty when using MockMvc, application/x-www-form-urlencoded and param #545
Comments
Thanks for the sample. On closer inspection, I'm not sure that this is a bug in REST Docs. When MockMvc is used to build an @Test
public void formUrlEncodedRequestBuiltWithParam() throws Exception {
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.patch("/foo")
.contentType(MediaType.APPLICATION_FORM_URLENCODED).param("a", "alpha")
.param("b", "bravo").buildRequest(new MockServletContext());
assertThat(mockRequest.getContentLength()).isGreaterThan(0);
assertThat(mockRequest.getContentAsString()).isNotEmpty();
} Interestingly, |
@rstoyanchev do you think |
FWIW, I thought it is impacted by these. CliOperationRequest.java#L56-L59 CurlRequestSnippet.java#L190-L192 |
Indeed; I'm aware of that code. I'd like to explore it becoming unnecessary though. At the moment, my opinion is that this should be handled in MockMvc (and REST Assured and WebTestClient if necessary) or, failing that, in REST Docs request converters. |
@rstoyanchev If you have a minute, I'd appreciate your input on my question above. |
In a Servlet container, query and form data are the source of request parameters. So if source data is provided, we'll parse that into request params. Or you can add request params directly, if you don't care about the source, but we won't go the other way around from the parsed representation to the source. There is ambiguity in trying to do that since technically a request could have both a query and form data. That said given that query parameters are specified through the URI in the So I'm not in favor of trying to interpret request parameters that way, but we could consider additional methods to explicitly add form data, something like For the |
Reproducible repository at: https://github.com/unlimitedsola/restdocs-empty-body-issue
The generated asciidoc doesn't contain any request body/parameter
The text was updated successfully, but these errors were encountered: