null
and ''
(empty string) are serializable to JSON and should therefore be considered a valid body payload
#1695
Labels
bug
Something isn't working
good first issue
Straightforward problem, solvable for first-time contributors without deep knowledge of the project
openapi-fetch
Relevant to the openapi-fetch library
PRs welcome
PRs are welcome to solve this issue!
Description
Calling the client with
body: null
orbody: ''
will result in no body sent to the server (same behavior as withundefined
).I believe that they should be serialized to
null
and""
respectively as these are valid JSON values and should be sent to the server.I believe the problem lies in this condition:
https://github.com/drwpow/openapi-typescript/blob/19ab7342594df2ec7bb60d891818fe22b3e96e38/packages/openapi-fetch/src/index.js#L79-L81
where it should rather use strict comparison:
requestInit.body !== undefined
.While the issue manifests only with
null
and''
, the problem is bigger here as any other falsy value (false
,0
) will bypass the body serializer too. They are sent "correctly" to the server, just because they fall back to default serialization provided by the browser, wherenull
and''
is apparently considered as "no-body".Reproduction
results in no body being sent.
results in body being sent, but does not yield
serializing
in the console.Expected result
All mentioned values go through the serializer and are sent to the server.
Checklist
The text was updated successfully, but these errors were encountered: