Skip to content

Conversation

@banseok1216
Copy link
Contributor

@banseok1216 banseok1216 commented Dec 1, 2025

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

  • Removes the fallback inference of application/x-www-form-urlencoded
  • Content-Type is now documented only when:
    • explicitly provided, or
    • required for multipart requests
  • Ensures requests with no Content-Type, no content, and no parts
    produce 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.

@wilkinsona
Copy link
Member

Thanks for the PR. Setting the Content-Type header for a PATCH, POST, or PUT request that has no body certainly seems wrong and I think that should be corrected. I am not so sure about removing it entirely as I wonder if it could be a breaking change for some situations. For 3.0.x at least, I think it would be better to only remove the setting of the Content-Type header for requests with no body content. A separate change that removes the inference entirely could then be considered for 4.0.x.

@wilkinsona wilkinsona added the status: waiting-for-feedback Feedback is required before progress can be made label Dec 1, 2025
@banseok1216 banseok1216 force-pushed the fix/content-type-inference branch from 8ef4042 to ba17f1c Compare December 1, 2025 13:24
@banseok1216
Copy link
Contributor Author

Thanks for the feedback. The PR has been updated as suggested.
We can look at removing the inference entirely in 4.0.x when the time comes.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback Feedback is required before progress can be made labels Dec 1, 2025
…out body

Signed-off-by: banseok1216 <bansuk1216@naver.com>
@banseok1216 banseok1216 force-pushed the fix/content-type-inference branch from ba17f1c to ec21a0e Compare December 1, 2025 13:33
@wilkinsona wilkinsona changed the title Fix incorrect Content-Type inference for POST/PUT/PATCH requests with… HTTP request snippet for PATCH, POST and PUT requests with no body has an incorrectly inferred Content-Type header Dec 1, 2025
@wilkinsona wilkinsona added type: bug A bug and removed status: waiting-for-triage Untriaged issue status: feedback-provided Feedback has been provided labels Dec 1, 2025
@wilkinsona wilkinsona added this to the 3.0.x milestone Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpRequestSnippet incorrectly infers Content-Type for POST/PUT/PATCH requests without a body

3 participants