swagger-api / swagger-api/swagger-codegen

[Javascript] collectionFormat which is set to multi don't work when content type is multipart/form-data

Open
#5,149 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: JavaScript/Node.js help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I want to have multi same parameter name when "multipart/form-data" is set to parameter type as "array" and collectionFormat is set to "multi".

Swagger-codegen version

latest

Swagger declaration file content or url
  consumes:
    - multipart/form-data
  parameters:
    - name: tags[]
      in: formData
      type: array
      collectionFormat: multi
      items:
        type: string
Command line used for generation

I use docker.

docker run --rm --name swagger_codegen_main_1 -w /gen -e GEN_DIR=/gen -v ~/docker/swagger-codegen:/gen -v /data/swagger_codegen:/local -v ~/.m2/repository:/root/.m2/repository --entrypoint /gen/docker-entrypoint.sh maven:3-jdk-7 generate -i /local/api.yaml -l javascript -o /local/out/javascript

Suggest a Fix

generated callApi in ApiClientjs

  exports.prototype.callApi = function callApi(path, httpMethod, pathParams,
      queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts,
      returnType, callback) {

    [snip]

    } else if (contentType == 'multipart/form-data') {
      var _formParams = this.normalizeParams(formParams);
      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]);
          }
        }
      }

    [snip]
  }

Should "request.field(key, _formParams[key])" be called multiple time when collectionFormat is multi and value type is array?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated callApi implementation in ApiClientjs and the supplied multipart/form-data Swagger declaration. Trace how array form parameters with collectionFormat set to multi are normalized and passed to request.field. Done means the generated JavaScript client preserves repeated parameter names for these values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.