-
Notifications
You must be signed in to change notification settings - Fork 249
Open
Description
Context
This bug affects POST/PUT/PATCH endpoints that lack a request body. When a request is made, a Content-Type: application/json
header is added, which can cause an error in the API as it attempts to decode a nonexistent request body.
Current Behavior
The "Try-it" feature and example snippets add a Content-Type: application/json
header to the request, even when no request body is specified in the spec for POST/PUT/PATCH endpoints.
Expected Behavior
If no request body is defined, the Content-Type
header should not be included.
Possible Workaround/Solution
- I understand there was a similar issue (Try-it: Content-type added even when no request body defined #2351) and a fix (Add Content-Type and Accept headers where necessary #2349), but from what I can tell, the fix only applies to GET endpoints.
- From what I gathered
- It seems the simplest solution is to return
undefined
fromgenerateExampleFromMediaTypeContent
whenmediaTypeContent
isundefined
. If this is actually the solution, happy to make a PR.
Steps to Reproduce
- Use this spec openapi.json in https://elements-demo.stoplight.io/
- You'll see the example
curl
snippet includeContent-Type

Environment
- Version used: 8.4.7
- Environment name and version (e.g. Chrome 39, node.js 5.4):
- Operating System and version (desktop or mobile):
- Link to your environment/workspace/project:
ismailkarsli
Metadata
Metadata
Assignees
Labels
No labels