You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Cannot pass a data-type object as an array of items in a form using Axios. It works perfectly for a normal object, but it's not working as expected for a form.
openapi-generator version
7.0.1
OpenAPI declaration file content or url
openapi: 3.0.3info:
title: Backendversion: 1.0.0paths:
/company:
put:
requestBody:
required: truecontent:
multipart/form-data:
schema:
$ref: '#/components/schemas/UpdateCompanyDetails'encoding:
industry:
contentType: application/jsonresponses:
'204':
description: The company data successfully updatedcomponents:
schemas:
UpdateCompanyDetails:
type: objectproperties:
name:
type: stringdescription: the name of the companyindustry:
type: arrayitems:
$ref: '#/components/schemas/Industry'currency:
$ref: '#/components/schemas/Currency'Industry:
type: objectproperties:
id:
type: integerdescription: The unique identifier of the industryname:
type: stringdescription: The name of the industryCurrency:
type: objectproperties:
id:
type: integerdescription: the unique identifier of the currencyname:
type: stringdescription: the long name of the currency (i.e. US Dollars)
Suggest a fix
{{#formParams}}
{{#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);
})
{{/contentType}}
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}}));
{{/isCollectionFormatMulti}}
}
{{/isArray}}
{{^isArray}}
if ({{paramName}} !== undefined) {
{{^multipartFormData}}
localVarFormParams.set('{{baseName}}', {{paramName}} as any);
{{/multipartFormData}}
{{#multipartFormData}}
{{#isPrimitiveType}}
localVarFormParams.append('{{baseName}}', {{paramName}} as any);
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isEnumRef}}
localVarFormParams.append('{{baseName}}', {{paramName}} as any);
{{/isEnumRef}}
{{^isEnumRef}}
localVarFormParams.append('{{baseName}}', new Blob([JSON.stringify({{paramName}})], { type: "application/json", }));
{{/isEnumRef}}
{{/isPrimitiveType}}
{{/multipartFormData}}
}
{{/isArray}}
{{/formParams}}
Currently, I'm using a custom template to check if any 'contentType' is defined, and if so, pass it as a blob and send it like this.
localVarFormParams.append('industry', new Blob([JSON.stringify(industry)], { type: 'application/json' }))
Actual output vs Expected output
Actual output
industry.forEach((element) => {
localVarFormParams.append('industry', element as any);
})
Expected output
localVarFormParams.append('industry', new Blob([JSON.stringify(industry)], { type: 'application/json' }))
The text was updated successfully, but these errors were encountered:
Also observing this bug. Would be great to get multipart working like this as I suspect it will also fix the issue where an array of files cannot be used in a multipart schema def
Bug Report Checklist
Description
Cannot pass a data-type object as an array of items in a form using Axios. It works perfectly for a normal object, but it's not working as expected for a form.
openapi-generator version
7.0.1
OpenAPI declaration file content or url
Suggest a fix
Currently, I'm using a custom template to check if any 'contentType' is defined, and if so, pass it as a blob and send it like this.
Actual output vs Expected output
Actual output
Expected output
The text was updated successfully, but these errors were encountered: