You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
shouldIncludeBodyhere is resolved to true as bodyInput is "".
Ultimately, the bodyInput comes from here ,which is set to "" in here when the mediaTypeContent is undefined which is the case when there is no requestBody.
It seems the simplest solution is to return undefined from generateExampleFromMediaTypeContent when mediaTypeContent is undefined. If this is actually the solution, happy to make a PR.
I'm not an expert in API design, but while it's uncommon to use a POST request without a body, it can be useful in certain scenarios. For example, consider POST /workflows/{id}/run, where the request triggers a state change. In this case, using POST is ideal because it indicates a mutation, even though no additional information is needed in the body.
Our use case is slightly more nuanced. In our situation, "getting" a resource induces side effects, including some state changes. Therefore, using POST is beneficial to accurately represent these side effects in the API and ensure the correct caching behavior.
I have opened #2739, please have a look when you have a moment. Thanks for your help.
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
shouldIncludeBody
here is resolved totrue
asbodyInput
is""
.bodyInput
comes from here ,which is set to""
in here when themediaTypeContent
isundefined
which is the case when there is norequestBody
.undefined
fromgenerateExampleFromMediaTypeContent
whenmediaTypeContent
isundefined
. If this is actually the solution, happy to make a PR.Steps to Reproduce
curl
snippet includeContent-Type
Environment
The text was updated successfully, but these errors were encountered: