Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form-data): handling array items #1336

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

BijanRegmi
Copy link
Contributor

Status

READY

Description

Fixes: #845

Formdata only supports either string or blob types. So items of an array should be converted to string before adding them to the form.

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

@melloware melloware requested a review from anymaniax April 29, 2024 16:44
@melloware melloware added the bug Something isn't working label Apr 29, 2024
@melloware melloware added this to the 6.28.0 milestone Apr 29, 2024
melloware
melloware previously approved these changes Apr 29, 2024
Copy link

@hariacharya80 hariacharya80 left a comment

Choose a reason for hiding this comment

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

Nice catch!

@melloware
Copy link
Collaborator

Looks like a formatting issue. Can you run npm run format please?

melloware
melloware previously approved these changes May 1, 2024
@Ultre00
Copy link

Ultre00 commented May 13, 2024

I see that the approved changes sets the data as a JSON string when itemSchema.type === 'object', This gets rid of the error, but doesn't realy make it form-data. Shouldn't each of the properties of the object also be iterated? And also add an array suffix to the key?

So that the end result looks something like this for the form data key: <arrayFieldName>[<arrayIndex>].<objectPropertyName>

@melloware melloware modified the milestones: 6.28.0, 6.29.0, 6.30.0 May 13, 2024
@melloware melloware modified the milestones: 6.30.0, 6.31.0 Jun 7, 2024
@melloware
Copy link
Collaborator

Looks like there is conflicts and an open question from @Ultre00

@melloware melloware modified the milestones: 6.31.0, 6.32.0 Jun 24, 2024
@BijanRegmi
Copy link
Contributor Author

I see that the approved changes sets the data as a JSON string when itemSchema.type === 'object', This gets rid of the error, but doesn't realy make it form-data. Shouldn't each of the properties of the object also be iterated? And also add an array suffix to the key?

So that the end result looks something like this for the form data key: <arrayFieldName>[<arrayIndex>].<objectPropertyName>

I think it's a personal opinion kind of thing. Surely <key1>.<key2> makes more sense for formdata but in most of the cases when transferring json data in formdata most tend to JSON.stringify the data and set content-type of the data to application/json

@BijanRegmi BijanRegmi requested a review from melloware June 26, 2024 12:10
@melloware
Copy link
Collaborator

@Ultre00 do you want to review the latest changes?

@Ultre00
Copy link

Ultre00 commented Jun 26, 2024

Isn't this change only related to formdata anyway? I don't see how setting content-type to application/json solves that issue as there was never a problem with that content-type. In my case, I couldn't use application/json as I want to send some files in the same request, so I am using multipart/form-data. I know there isn't really a standard defined on how to handle nested objects/arrays. What I suggested is just what .NET expects, I guess.

I don't think there is anything else to review. Only Main is merged into this branch.

@melloware
Copy link
Collaborator

@Ultre00 @BijanRegmi where are we with this PR? Is there more work to be done?

@BijanRegmi
Copy link
Contributor Author

It's ready to be merged

@melloware melloware merged commit 238dfa4 into orval-labs:master Jul 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS Error: argument of type 'number' is not assignable to parameter of type 'string | Blob'
4 participants