Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 7db7785

Browse files
authored
Release 9.1.1 (acacode#263)
* fix: bug with nested object in form data * bump: up version to 9.1.1
1 parent 10f0df3 commit 7db7785

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+743
-206
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# next release
22

3+
# 9.1.1
4+
5+
Fixes:
6+
- Bug with nested objects in FormData (issue #262, thanks @avlnche64)
7+
38
# 9.1.0
49

510
Fixes:

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "9.1.0",
3+
"version": "9.1.1",
44
"description": "Generate typescript/javascript api from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",

templates/base/http-clients/axios-http-client.eta

+16-5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ export class HttpClient<SecurityDataType = unknown> {
6666
};
6767
}
6868

69+
private createFormData(input: Record<string, unknown>): FormData {
70+
return Object.keys(input || {}).reduce((formData, key) => {
71+
const property = input[key];
72+
formData.append(
73+
key,
74+
property instanceof Blob ?
75+
property :
76+
typeof property === "object" && property !== null ?
77+
JSON.stringify(property) :
78+
`${property}`
79+
);
80+
return formData;
81+
}, new FormData())
82+
}
83+
6984
public request = async <T = any, _E = any>({
7085
secure,
7186
path,
@@ -84,11 +99,7 @@ export class HttpClient<SecurityDataType = unknown> {
8499
requestParams.headers.post = {};
85100
requestParams.headers.put = {};
86101

87-
const formData = new FormData();
88-
for (const key in body) {
89-
formData.append(key, body[key as keyof typeof body]);
90-
}
91-
body = formData;
102+
const formData = this.createFormData(body as Record<string, unknown>);
92103
}
93104

94105
return this.instance.request({

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,18 @@ export class HttpClient<SecurityDataType = unknown> {
103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104104
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105105
[ContentType.FormData]: (input: any) =>
106-
Object.keys(input || {}).reduce((data, key) => {
107-
data.append(key, input[key]);
108-
return data;
109-
}, new FormData()),
106+
Object.keys(input || {}).reduce((formData, key) => {
107+
const property = input[key];
108+
formData.append(
109+
key,
110+
property instanceof Blob ?
111+
property :
112+
typeof property === "object" && property !== null ?
113+
JSON.stringify(property) :
114+
`${property}`
115+
);
116+
return formData;
117+
}, new FormData()),
110118
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
111119
}
112120

tests/generated/v2.0/adafruit.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,17 @@ export class HttpClient<SecurityDataType = unknown> {
261261
[ContentType.Json]: (input: any) =>
262262
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
263263
[ContentType.FormData]: (input: any) =>
264-
Object.keys(input || {}).reduce((data, key) => {
265-
data.append(key, input[key]);
266-
return data;
264+
Object.keys(input || {}).reduce((formData, key) => {
265+
const property = input[key];
266+
formData.append(
267+
key,
268+
property instanceof Blob
269+
? property
270+
: typeof property === "object" && property !== null
271+
? JSON.stringify(property)
272+
: `${property}`,
273+
);
274+
return formData;
267275
}, new FormData()),
268276
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
269277
};

tests/generated/v2.0/another-example.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,17 @@ export class HttpClient<SecurityDataType = unknown> {
237237
[ContentType.Json]: (input: any) =>
238238
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
239239
[ContentType.FormData]: (input: any) =>
240-
Object.keys(input || {}).reduce((data, key) => {
241-
data.append(key, input[key]);
242-
return data;
240+
Object.keys(input || {}).reduce((formData, key) => {
241+
const property = input[key];
242+
formData.append(
243+
key,
244+
property instanceof Blob
245+
? property
246+
: typeof property === "object" && property !== null
247+
? JSON.stringify(property)
248+
: `${property}`,
249+
);
250+
return formData;
243251
}, new FormData()),
244252
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
245253
};

tests/generated/v2.0/another-schema.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ export class HttpClient<SecurityDataType = unknown> {
129129
[ContentType.Json]: (input: any) =>
130130
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
131131
[ContentType.FormData]: (input: any) =>
132-
Object.keys(input || {}).reduce((data, key) => {
133-
data.append(key, input[key]);
134-
return data;
132+
Object.keys(input || {}).reduce((formData, key) => {
133+
const property = input[key];
134+
formData.append(
135+
key,
136+
property instanceof Blob
137+
? property
138+
: typeof property === "object" && property !== null
139+
? JSON.stringify(property)
140+
: `${property}`,
141+
);
142+
return formData;
135143
}, new FormData()),
136144
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
137145
};

tests/generated/v2.0/api-with-examples.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,17 @@ export class HttpClient<SecurityDataType = unknown> {
106106
[ContentType.Json]: (input: any) =>
107107
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
108108
[ContentType.FormData]: (input: any) =>
109-
Object.keys(input || {}).reduce((data, key) => {
110-
data.append(key, input[key]);
111-
return data;
109+
Object.keys(input || {}).reduce((formData, key) => {
110+
const property = input[key];
111+
formData.append(
112+
key,
113+
property instanceof Blob
114+
? property
115+
: typeof property === "object" && property !== null
116+
? JSON.stringify(property)
117+
: `${property}`,
118+
);
119+
return formData;
112120
}, new FormData()),
113121
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
114122
};

tests/generated/v2.0/authentiq.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,17 @@ export class HttpClient<SecurityDataType = unknown> {
158158
[ContentType.Json]: (input: any) =>
159159
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
160160
[ContentType.FormData]: (input: any) =>
161-
Object.keys(input || {}).reduce((data, key) => {
162-
data.append(key, input[key]);
163-
return data;
161+
Object.keys(input || {}).reduce((formData, key) => {
162+
const property = input[key];
163+
formData.append(
164+
key,
165+
property instanceof Blob
166+
? property
167+
: typeof property === "object" && property !== null
168+
? JSON.stringify(property)
169+
: `${property}`,
170+
);
171+
return formData;
164172
}, new FormData()),
165173
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
166174
};

tests/generated/v2.0/enums.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,17 @@ export class HttpClient<SecurityDataType = unknown> {
171171
[ContentType.Json]: (input: any) =>
172172
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
173173
[ContentType.FormData]: (input: any) =>
174-
Object.keys(input || {}).reduce((data, key) => {
175-
data.append(key, input[key]);
176-
return data;
174+
Object.keys(input || {}).reduce((formData, key) => {
175+
const property = input[key];
176+
formData.append(
177+
key,
178+
property instanceof Blob
179+
? property
180+
: typeof property === "object" && property !== null
181+
? JSON.stringify(property)
182+
: `${property}`,
183+
);
184+
return formData;
177185
}, new FormData()),
178186
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
179187
};

tests/generated/v2.0/example1.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,17 @@ export class HttpClient<SecurityDataType = unknown> {
133133
[ContentType.Json]: (input: any) =>
134134
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
135135
[ContentType.FormData]: (input: any) =>
136-
Object.keys(input || {}).reduce((data, key) => {
137-
data.append(key, input[key]);
138-
return data;
136+
Object.keys(input || {}).reduce((formData, key) => {
137+
const property = input[key];
138+
formData.append(
139+
key,
140+
property instanceof Blob
141+
? property
142+
: typeof property === "object" && property !== null
143+
? JSON.stringify(property)
144+
: `${property}`,
145+
);
146+
return formData;
139147
}, new FormData()),
140148
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
141149
};

tests/generated/v2.0/file-formdata-example.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,17 @@ export class HttpClient<SecurityDataType = unknown> {
106106
[ContentType.Json]: (input: any) =>
107107
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
108108
[ContentType.FormData]: (input: any) =>
109-
Object.keys(input || {}).reduce((data, key) => {
110-
data.append(key, input[key]);
111-
return data;
109+
Object.keys(input || {}).reduce((formData, key) => {
110+
const property = input[key];
111+
formData.append(
112+
key,
113+
property instanceof Blob
114+
? property
115+
: typeof property === "object" && property !== null
116+
? JSON.stringify(property)
117+
: `${property}`,
118+
);
119+
return formData;
112120
}, new FormData()),
113121
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
114122
};

tests/generated/v2.0/furkot-example.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,17 @@ export class HttpClient<SecurityDataType = unknown> {
169169
[ContentType.Json]: (input: any) =>
170170
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
171171
[ContentType.FormData]: (input: any) =>
172-
Object.keys(input || {}).reduce((data, key) => {
173-
data.append(key, input[key]);
174-
return data;
172+
Object.keys(input || {}).reduce((formData, key) => {
173+
const property = input[key];
174+
formData.append(
175+
key,
176+
property instanceof Blob
177+
? property
178+
: typeof property === "object" && property !== null
179+
? JSON.stringify(property)
180+
: `${property}`,
181+
);
182+
return formData;
175183
}, new FormData()),
176184
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
177185
};

tests/generated/v2.0/giphy.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,17 @@ export class HttpClient<SecurityDataType = unknown> {
388388
[ContentType.Json]: (input: any) =>
389389
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
390390
[ContentType.FormData]: (input: any) =>
391-
Object.keys(input || {}).reduce((data, key) => {
392-
data.append(key, input[key]);
393-
return data;
391+
Object.keys(input || {}).reduce((formData, key) => {
392+
const property = input[key];
393+
formData.append(
394+
key,
395+
property instanceof Blob
396+
? property
397+
: typeof property === "object" && property !== null
398+
? JSON.stringify(property)
399+
: `${property}`,
400+
);
401+
return formData;
394402
}, new FormData()),
395403
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
396404
};

tests/generated/v2.0/github-swagger.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1541,9 +1541,17 @@ export class HttpClient<SecurityDataType = unknown> {
15411541
[ContentType.Json]: (input: any) =>
15421542
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
15431543
[ContentType.FormData]: (input: any) =>
1544-
Object.keys(input || {}).reduce((data, key) => {
1545-
data.append(key, input[key]);
1546-
return data;
1544+
Object.keys(input || {}).reduce((formData, key) => {
1545+
const property = input[key];
1546+
formData.append(
1547+
key,
1548+
property instanceof Blob
1549+
? property
1550+
: typeof property === "object" && property !== null
1551+
? JSON.stringify(property)
1552+
: `${property}`,
1553+
);
1554+
return formData;
15471555
}, new FormData()),
15481556
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
15491557
};

tests/generated/v2.0/path-args.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,17 @@ export class HttpClient<SecurityDataType = unknown> {
106106
[ContentType.Json]: (input: any) =>
107107
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
108108
[ContentType.FormData]: (input: any) =>
109-
Object.keys(input || {}).reduce((data, key) => {
110-
data.append(key, input[key]);
111-
return data;
109+
Object.keys(input || {}).reduce((formData, key) => {
110+
const property = input[key];
111+
formData.append(
112+
key,
113+
property instanceof Blob
114+
? property
115+
: typeof property === "object" && property !== null
116+
? JSON.stringify(property)
117+
: `${property}`,
118+
);
119+
return formData;
112120
}, new FormData()),
113121
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
114122
};

tests/generated/v2.0/petstore-expanded.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,17 @@ export class HttpClient<SecurityDataType = unknown> {
143143
[ContentType.Json]: (input: any) =>
144144
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
145145
[ContentType.FormData]: (input: any) =>
146-
Object.keys(input || {}).reduce((data, key) => {
147-
data.append(key, input[key]);
148-
return data;
146+
Object.keys(input || {}).reduce((formData, key) => {
147+
const property = input[key];
148+
formData.append(
149+
key,
150+
property instanceof Blob
151+
? property
152+
: typeof property === "object" && property !== null
153+
? JSON.stringify(property)
154+
: `${property}`,
155+
);
156+
return formData;
149157
}, new FormData()),
150158
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
151159
};

tests/generated/v2.0/petstore-minimal.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,17 @@ export class HttpClient<SecurityDataType = unknown> {
114114
[ContentType.Json]: (input: any) =>
115115
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
116116
[ContentType.FormData]: (input: any) =>
117-
Object.keys(input || {}).reduce((data, key) => {
118-
data.append(key, input[key]);
119-
return data;
117+
Object.keys(input || {}).reduce((formData, key) => {
118+
const property = input[key];
119+
formData.append(
120+
key,
121+
property instanceof Blob
122+
? property
123+
: typeof property === "object" && property !== null
124+
? JSON.stringify(property)
125+
: `${property}`,
126+
);
127+
return formData;
120128
}, new FormData()),
121129
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
122130
};

tests/generated/v2.0/petstore-simple.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ export class HttpClient<SecurityDataType = unknown> {
129129
[ContentType.Json]: (input: any) =>
130130
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
131131
[ContentType.FormData]: (input: any) =>
132-
Object.keys(input || {}).reduce((data, key) => {
133-
data.append(key, input[key]);
134-
return data;
132+
Object.keys(input || {}).reduce((formData, key) => {
133+
const property = input[key];
134+
formData.append(
135+
key,
136+
property instanceof Blob
137+
? property
138+
: typeof property === "object" && property !== null
139+
? JSON.stringify(property)
140+
: `${property}`,
141+
);
142+
return formData;
135143
}, new FormData()),
136144
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
137145
};

0 commit comments

Comments
 (0)