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
  • #7913
Closed
Open
Issue created Nov 10, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [JS] Multi File Upload is not supported

Created by: tray2100

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

There doesn't seem to be support for multi file upload in the JS generator. The current implementation only supports a parameter being a single file and not a collection of files.

You can see this here where only

     for (var key in _formParams) {
        if (_formParams.hasOwnProperty(key)) {
          if (this.isFileParam(_formParams[key])) {
            // file field
            request.attach(key, _formParams[key]);
          } else {
            request.field(key, _formParams[key]);
          }
        }
      }

Additionally, the Code Generator defaults collections to the collection format csv which doesn't work for File objects. The more ideal thing would be to let superagent handle it and pass through the incoming collection.

openapi-generator version

4.3.1 ... doesn't look to be a regression. Just missing handling

OpenAPI declaration file content or url

There's already a schema that shows this issue: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/form-multipart-binary-array.yaml

paths:
  /multipart-array:
    post:
      tags:
        - multipart
      description: MultipartFile array test
      operationId: multipartArray
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                files:
                  type: array
                  description: "Many files"
                  items:
                    type: string
                    format: binary
Steps to reproduce

Generate JS code for this schema and you'll see that

Related issues/PRs
Suggest a fix

Add support for adding multiple files as individual parts to the request

     for (var key in _formParams) {
        if (_formParams.hasOwnProperty(key)) {
          let _formParamsValue = _formParams[key];
          if (this.isFileParam(_formParamsValue)) {
            // file field
            request.attach(key, _formParamsValue);
          } else if (Array.isArray(_formParamsValue) && _formParamsValue.length  
            && this.isFileParam(_formParamsValue[0])) {
            // multiple files
            _formParamsValue.forEach(file => request.attach(key, file));
          } else {
            request.field(key, _formParamsValue);
          }
        }
      }

Support collections of files better:

       var formParams = {
         'request': opts['request'],
         'files': this.apiClient.buildCollectionParam(opts['files'], 'passthrough')
       };

where passthrough causes buildCollectionParam to return the input array.

Assignee
Assign to
Time tracking