diff --git a/package.json b/package.json index db3bdce33..5b31e14a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swagger-typescript-api", - "version": "13.0.26", + "version": "13.0.27", "description": "Generate the API client for Fetch or Axios from an OpenAPI Specification", "homepage": "https://github.com/acacode/swagger-typescript-api", "bugs": "https://github.com/acacode/swagger-typescript-api/issues", diff --git a/templates/base/http-clients/fetch-http-client.ejs b/templates/base/http-clients/fetch-http-client.ejs index a1db3833e..9a05fc0d7 100644 --- a/templates/base/http-clients/fetch-http-client.ejs +++ b/templates/base/http-clients/fetch-http-client.ejs @@ -106,16 +106,28 @@ export class HttpClient { [ContentType.Text]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((formData, key) => { - const property = input[key]; - formData.append( + const property = input[key]; + + // array of property should be added item by item in formData with the same key + if (Array.isArray(property)) { + for (const item of property) { + formData.append( key, - property instanceof Blob ? - property : - typeof property === "object" && property !== null ? - JSON.stringify(property) : - `${property}` + item instanceof Blob ? item : typeof item === "object" && item !== null ? JSON.stringify(item) : `${item}` + ); + } + } else { + formData.append( + key, + property instanceof Blob + ? property + : typeof property === "object" && property !== null + ? JSON.stringify(property) + : `${property}` ); - return formData; + } + + return formData; }, new FormData()), [ContentType.UrlEncoded]: (input: any) => this.toQueryString(input), }