HTTP request snippet for PATCH, POST and PUT requests with no body has an incorrectly inferred Content-Type header#1018
Conversation
33a16d3 to
8467729
Compare
|
Thanks for the PR. Setting the |
8ef4042 to
ba17f1c
Compare
|
Thanks for the feedback. The PR has been updated as suggested. |
ba17f1c to
ec21a0e
Compare
| String body = "a=alpha&b=bravo"; | ||
| new HttpRequestSnippet().document(operationBuilder.request("http://localhost/foo") | ||
| .method("POST") | ||
| .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) |
There was a problem hiding this comment.
This test passes both with and without the proposed change to HttpRequestSnippet so I don't think I understand its intent. Given that the bug occurs when there's no content type header in the request, why is this new test creating a request with a content type header?
There was a problem hiding this comment.
Sorry, that was my mistake — while verifying the fix I ended up adding the wrong test.
I replace the tests to cover the actual bug case.
…out body Signed-off-by: banseok1216 <bansuk1216@naver.com>
ec21a0e to
d0f11e8
Compare
Closes #1017
Summary
REST Docs previously inferred Content-Type: application/x-www-form-urlencoded
when processing POST/PUT/PATCH requests that had no Content-Type, no body, and no parts.
This caused the generated documentation to differ from the real request seen by Spring MVC.
What this PR changes
application/x-www-form-urlencodedproduce no Content-Type header in the generated snippet
Rationale
Documentation should reflect the exact request sent by the client.
HTTP provides no default media type, and Spring MVC does not infer one.
Avoiding implicit Content-Type injection ensures accuracy and prevents misleading API documentation.