Skip to content

typescript-fetch: Properly detect and encode container request body param#3517

Merged
macjohnny merged 1 commit intoOpenAPITools:masterfrom
someone1:fix-3278
Aug 5, 2019
Merged

typescript-fetch: Properly detect and encode container request body param#3517
macjohnny merged 1 commit intoOpenAPITools:masterfrom
someone1:fix-3278

Conversation

@someone1
Copy link
Contributor

@someone1 someone1 commented Jul 31, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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.sh if 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.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body is a string now. Does this work correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange, but how can this


work, it is also a object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is converted here:

const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);

so JSON.stringify is not necessary here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - did not catch that, thanks!

…aram

Signed-off-by: Prateek Malhotra <someone1@gmail.com>
Co-Authored-By: Esteban Gehring <esteban.gehring@gmail.com>
Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@macjohnny macjohnny merged commit f756bd5 into OpenAPITools:master Aug 5, 2019
@macjohnny macjohnny added this to the 4.1.0 milestone Aug 5, 2019
@wing328
Copy link
Member

wing328 commented Aug 10, 2019

@someone1 thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][typescript-fetch] Schema with type array generates undefined function

3 participants

Comments