@@ -66,16 +66,36 @@ export class HttpClient<SecurityDataType = unknown> {
6666 };
6767 }
6868
69+ private stringifyItem(item: any): string {
70+ if (typeof item === "object" && item !== null) {
71+ return JSON.stringify(item);
72+ }
73+
74+ return `${item}`;
75+ }
76+
6977 private createFormData(input: Record<string, unknown>): FormData {
78+ return Object.keys(input || {}).reduce((formData, key) => {
79+ const property = input[key];
80+ const propertyContent: Iterable<any> = (property instanceof Array) ? property : [property]
81+
82+ for (const formItem of propertyContent) {
83+ const isFileType = formItem instanceof Blob || formItem instanceof File;
84+ formData.append(
85+ key,
86+ isFileType
87+ ? formItem
88+ : this.stringifyItem(formItem),
89+ );
90+ }
91+
92+ return formData;
93+ }, new FormData());
7094 return Object.keys(input || {}).reduce((formData, key) => {
7195 const property = input[key];
7296 formData.append(
7397 key,
74- property instanceof Blob ?
75- property :
76- typeof property === "object" && property !== null ?
77- JSON.stringify(property) :
78- `${property}`
98+ property instanceof Blob ? property : this.stringifyItem(property),
7999 );
80100 return formData;
81101 }, new FormData())
@@ -96,7 +116,7 @@ export class HttpClient<SecurityDataType = unknown> {
96116<% } %>
97117 const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {};
98118 const requestParams = this.mergeRequestParams(params, secureParams);
99- const responseFormat = (format && this.format) || void 0 ;
119+ const responseFormat = (format || this.format) || undefined ;
100120
101121 if (type === ContentType.FormData && body && body !== null && typeof body === "object") {
102122 requestParams.headers.common = { Accept: "*/*" };
0 commit comments