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

Support Arrays in multipart/form-data #1367

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-needles-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-client": patch
---

Support arrays in multipart/form-data
14 changes: 13 additions & 1 deletion packages/plugin-client/src/components/Client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,28 @@ export function Client({
const formData = isFormData
? `
const formData = new FormData()

if(data) {

Object.keys(data).forEach((key) => {
const value = data[key as keyof typeof data];

if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
formData.append(key, value);
}

if(Array.isArray(value)) {
for(let i = 0; i < value.length; i++) { //for performance reasons, cause the code is generated anyways
const arrValue = value[i];
if (typeof arrValue === "string" || arrValue instanceof Blob) {
formData.append(key, value);
}
}
}
})
}
`
: ''
: "";

return (
<File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
Expand Down