From 73f2d8289b2d4069675c79ea5375d9c58ea1853c Mon Sep 17 00:00:00 2001 From: Hidan Date: Fri, 3 May 2024 19:13:57 +0530 Subject: [PATCH] fix(typescript-axios): Correct the content type for a list of objects in form-data when contentType is present (#18505) * fix content type for list of objects in form-data * updated the samples --- .../src/main/resources/typescript-axios/apiInner.mustache | 7 ++++++- samples/client/echo_api/typescript-axios/build/api.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache index e008a6d830ec..7ad585b93785 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache @@ -189,9 +189,14 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur {{#isArray}} if ({{paramName}}) { {{#isCollectionFormatMulti}} + {{#contentType}} + localVarFormParams.append('{{baseName}}', new Blob([JSON.stringify({{paramName}})], { type: "{{contentType}}", })); + {{/contentType}} + {{^contentType}} {{paramName}}.forEach((element) => { - localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', element as any); + localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', element as any); }) + {{/contentType}} {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}})); diff --git a/samples/client/echo_api/typescript-axios/build/api.ts b/samples/client/echo_api/typescript-axios/build/api.ts index 384ba1cdfc3c..f22a7e72ccaf 100644 --- a/samples/client/echo_api/typescript-axios/build/api.ts +++ b/samples/client/echo_api/typescript-axios/build/api.ts @@ -615,7 +615,7 @@ export const BodyApiAxiosParamCreator = function (configuration?: Configuration) if (files) { files.forEach((element) => { - localVarFormParams.append('files', element as any); + localVarFormParams.append('files', element as any); }) }