swagger-api / swagger-api/swagger-codegen

[typescript-angular] File arrays do not use FormData

Open
#9,090 3 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When a formData file parameter is an array, the generated code does not properly trigger the use of FormData. The generated code works properly be manually changing the below line in the generated service method:

let useForm = false;

to

let useForm = canConsumeForm;
Swagger declaration file content or url
post:
      operationId: UploadFiles
      tags:
        - Documents
      summary: Creates a new document with a single revision.
      consumes:
        - multipart/form-data
      parameters:
        - name: files
          in: formData
          type: array
          items:
            type: file
      responses:
        '201':
          description: Document created successfully
          schema:
            $ref: '#/definitions/DocumentSummaryResponse'
      produces:
        - application/json
Suggest a fix/enhancement

In addition to checking if the parameter is of type file, the code gen logic should also check if the items.type parameter is of type file. If so, set the isFile flag to true.

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 at the TypeScript Angular generator logic that determines whether a formData parameter is a file, using the generated service method and the provided Swagger declaration as the reproduction. Check the existing file-parameter condition against array items.type; done when an array of files causes useForm to use canConsumeForm without manual edits.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.