Skip to content

Commit 0d80f8e

Browse files
JorensMsmorimoto
authored andcommitted
Fix contentFormatter for FormData returning an empty FormData object
1 parent 9ac09e4 commit 0d80f8e

File tree

25 files changed

+320
-320
lines changed

25 files changed

+320
-320
lines changed

templates/base/http-clients/fetch-http-client.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ export class HttpClient<SecurityDataType = unknown> {
104104
private contentFormatters: Record<ContentType, (input: any) => any> = {
105105
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
106106
[ContentType.Text]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input,
107-
[ContentType.FormData]: (input: any) =>
108-
Object.keys(input || {}).reduce((formData, key) => {
109-
const property = input[key];
107+
[ContentType.FormData]: (input: FormData) =>
108+
(Array.from(input.keys()) || []).reduce((formData, key) => {
109+
const property = input.get(key);
110110
formData.append(
111111
key,
112112
property instanceof Blob ?

tests/__snapshots__/extended.test.ts.snap

Lines changed: 126 additions & 126 deletions
Large diffs are not rendered by default.

tests/__snapshots__/simple.test.ts.snap

Lines changed: 126 additions & 126 deletions
Large diffs are not rendered by default.

tests/spec/another-query-params/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ export class HttpClient<SecurityDataType = unknown> {
138138
[ContentType.Json]: (input: any) =>
139139
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
140140
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
141-
[ContentType.FormData]: (input: any) =>
142-
Object.keys(input || {}).reduce((formData, key) => {
143-
const property = input[key];
141+
[ContentType.FormData]: (input: FormData) =>
142+
(Array.from(input.keys()) || []).reduce((formData, key) => {
143+
const property = input.get(key);
144144
formData.append(
145145
key,
146146
property instanceof Blob

tests/spec/custom-extensions/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export class HttpClient<SecurityDataType = unknown> {
110110
[ContentType.Json]: (input: any) =>
111111
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
112112
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
113-
[ContentType.FormData]: (input: any) =>
114-
Object.keys(input || {}).reduce((formData, key) => {
115-
const property = input[key];
113+
[ContentType.FormData]: (input: FormData) =>
114+
(Array.from(input.keys()) || []).reduce((formData, key) => {
115+
const property = input.get(key);
116116
formData.append(
117117
key,
118118
property instanceof Blob

tests/spec/defaultAsSuccess/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ export class HttpClient<SecurityDataType = unknown> {
150150
[ContentType.Json]: (input: any) =>
151151
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
152152
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
153-
[ContentType.FormData]: (input: any) =>
154-
Object.keys(input || {}).reduce((formData, key) => {
155-
const property = input[key];
153+
[ContentType.FormData]: (input: FormData) =>
154+
(Array.from(input.keys()) || []).reduce((formData, key) => {
155+
const property = input.get(key);
156156
formData.append(
157157
key,
158158
property instanceof Blob

tests/spec/defaultResponse/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export class HttpClient<SecurityDataType = unknown> {
110110
[ContentType.Json]: (input: any) =>
111111
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
112112
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
113-
[ContentType.FormData]: (input: any) =>
114-
Object.keys(input || {}).reduce((formData, key) => {
115-
const property = input[key];
113+
[ContentType.FormData]: (input: FormData) =>
114+
(Array.from(input.keys()) || []).reduce((formData, key) => {
115+
const property = input.get(key);
116116
formData.append(
117117
key,
118118
property instanceof Blob

tests/spec/deprecated/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export class HttpClient<SecurityDataType = unknown> {
110110
[ContentType.Json]: (input: any) =>
111111
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
112112
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
113-
[ContentType.FormData]: (input: any) =>
114-
Object.keys(input || {}).reduce((formData, key) => {
115-
const property = input[key];
113+
[ContentType.FormData]: (input: FormData) =>
114+
(Array.from(input.keys()) || []).reduce((formData, key) => {
115+
const property = input.get(key);
116116
formData.append(
117117
key,
118118
property instanceof Blob

tests/spec/dot-path-params/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ export class HttpClient<SecurityDataType = unknown> {
112112
[ContentType.Json]: (input: any) =>
113113
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
114114
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
115-
[ContentType.FormData]: (input: any) =>
116-
Object.keys(input || {}).reduce((formData, key) => {
117-
const property = input[key];
115+
[ContentType.FormData]: (input: FormData) =>
116+
(Array.from(input.keys()) || []).reduce((formData, key) => {
117+
const property = input.get(key);
118118
formData.append(
119119
key,
120120
property instanceof Blob

tests/spec/enumNamesAsValues/__snapshots__/basic.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ export class HttpClient<SecurityDataType = unknown> {
302302
[ContentType.Json]: (input: any) =>
303303
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
304304
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
305-
[ContentType.FormData]: (input: any) =>
306-
Object.keys(input || {}).reduce((formData, key) => {
307-
const property = input[key];
305+
[ContentType.FormData]: (input: FormData) =>
306+
(Array.from(input.keys()) || []).reduce((formData, key) => {
307+
const property = input.get(key);
308308
formData.append(
309309
key,
310310
property instanceof Blob

0 commit comments

Comments
 (0)