[Bug][typescript-axios] When Multiple File Uploaded, it does not work as isCollectionFormatMulti
Created by: shrkw
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
I want to define api for 'Multiple File Upload' which refer the part in swagger document File Upload. But the generated script deals with binaries as simple string.
localVarFormParams.append('files', files.join(COLLECTION_FORMATS.csv));
openapi-generator version
v4.3.1
OpenAPI declaration file content or url
I added encoding parameter to force form style but not works well.
openapi: 3.0.3
info:
title: test
version: '0.1'
tags:
- name: test
description: test
servers:
- url: 'http://localhost:3000'
paths:
/api/upload:
post:
tags: []
operationId: upload files
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
message:
type: string
files:
type: array
items:
type: string
format: binary
required:
- message
encoding:
files:
style: form
explode: true
responses:
'200':
description: ok
Generation Details
use this command.
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v4.3.1 generate \
-p supportsES6=true \
-p modelPropertyNaming=camelCase \
-i /local/doc/test.yaml \
-g typescript-axios \
-o /local/app/javascript --verbose
Steps to reproduce
just run by above command, then it generate following script.
if (files) {
localVarFormParams.append('files', files.join(COLLECTION_FORMATS.csv));
}
here is verbose output https://gist.github.com/shrkw/5002c71e33177b99c0529f1506d6ff22
and api.ts https://gist.github.com/shrkw/5002c71e33177b99c0529f1506d6ff22#file-api-ts-L77
Related issues/PRs
Not sure but may be same issue.
BUG multi file upload not implemented fully · Issue #6752 · OpenAPITools/openapi-generator · GitHub
Same issue is facing to this guy. BUGJavaSpring multiple files upload · Issue #4803 · OpenAPITools/openapi-generator · GitHub
Suggest a fix
I want to set isCollectionFormatMulti attribute, but not sure how to do it.
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
localVarFormParams.append('{{baseName}}', element as any);
})
{{/isCollectionFormatMulti}}