Skip to content

Commit 7db7785

Browse files
authored
Release 9.1.1 (#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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 5 deletions
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

Lines changed: 12 additions & 4 deletions
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

Lines changed: 11 additions & 3 deletions
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

Lines changed: 11 additions & 3 deletions
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

Lines changed: 11 additions & 3 deletions
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

Lines changed: 11 additions & 3 deletions
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

Lines changed: 11 additions & 3 deletions
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
};

0 commit comments

Comments
 (0)