Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7247
Closed
Open
Issue created Aug 19, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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.

openapi-generator/apiInner.mustache at f752f29af202885e6b817e5ec002facee1ef0c33 · OpenAPITools/openapi-generator · GitHub

            {{#isCollectionFormatMulti}}
                {{paramName}}.forEach((element) => {
                    localVarFormParams.append('{{baseName}}', element as any);
                })
            {{/isCollectionFormatMulti}}
Assignee
Assign to
Time tracking