typescript-fetch: Properly detect and encode container request body param#3517
typescript-fetch: Properly detect and encode container request body param#3517macjohnny merged 1 commit intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
The body is a string now. Does this work correctly?
There was a problem hiding this comment.
According to the Fetch API:
body: Any body that you want to add to your request: this can be a Blob, BufferSource, FormData, URLSearchParams, or USVString object. Note that a request using the GET or HEAD method cannot have a body.
Passing random objects and lists on my local results in a nonsense body value of [object Object]. I believe this has always been broken.
There was a problem hiding this comment.
strange, but how can this
work, it is also a object
There was a problem hiding this comment.
it is converted here:
so JSON.stringify is not necessary here
There was a problem hiding this comment.
I see - did not catch that, thanks!
modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache
Outdated
Show resolved
Hide resolved
…aram Signed-off-by: Prateek Malhotra <someone1@gmail.com> Co-Authored-By: Esteban Gehring <esteban.gehring@gmail.com>
|
@someone1 thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553 |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master,4.1.x,5.0.x. Default:master.Description of the PR
Passing lists/containers to the body param as-is will send garbage via
fetch- needed to stringify the contents first and only map over the items if it was a list of non-primitives.fixes #3278
@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07)