OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-axios] Upload file with multipart misses to add boundary with node

Open
#8,002 3 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

When using typescript-axios in a node environment, it's not able to upload a image because axios does not automatically add the boundary to the header, ref see here.

openapi-generator version

2.1.6

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Bug API
  version: 1.0.0
tags:
  - name: image
    description: Upload a image
paths:
  /image:
    put:
      tags:
        - image
      summary: Update current map image
      operationId: setImage
      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                file:
                  type: string
                  format: binary
                  description: The file to upload
      responses:
        200:
          description: Image successful uploaded
Generation Details
npx @openapitools/openapi-generator-cli generate -i bug-spec.yaml -g typescript-axios --additional-properties supportsES6=true -o generated
Steps to reproduce

Execute the command above and take a look at ImageApiAxiosParamCreator:54.

localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
Related issues/PRs
Suggest a fix

I already have an idea how it could be fixed, but I have to say that I only have beginner experience, so please check if it makes sense.

if (typeof((localVarFormParams as any).getHeaders) === 'function') {
  const headers = (localVarFormParams as any).getHeaders();
  for (const [key, value] of Object.entries(headers)) {
    localVarHeaderParameter[key] = value;
  }
} else {
  localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
}

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

Reproduce the issue with the provided OpenAPI declaration and typescript-axios generation command, then inspect ImageApiAxiosParamCreator:54 in the generated output. Verify the Node multipart upload sends the boundary in its Content-Type header; the issue is done when the generated client uploads the image successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.