OpenAPITools / OpenAPITools/openapi-generator

[BUG][Typescript Axios] Content-type not set

Open
#2,694 11 comments 1 reaction 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

Description

Typescript axios generators does not handle correctly multipart requests. Content-Type header is never set.

openapi-generator version

4.0.0-beta3

OpenAPI declaration file content or url
openapi: 3.0.0

paths:
  'upload':
    post:
      summary: Upload File
      description: ''
      operationId: uploadFile
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/logoForCreation'
            encoding:
              medicalCertificateFileName:
                contentType: image/png, image/jpeg

        required:
          true
        description: body
      responses:
        201:
          description: Created or updated club's logo
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/photo'
components:
  schemas:
    logoForCreation:
      type: object
      required:
        - logoFileName
      properties:
        logoFileName:
          type: string
          format: binary
    photo:
      required:
        - location
      properties:
        location:
          type: string
Command line used for generation

openapi-generator generate -i swagger.yaml -g typescript-axios -o src/generated --skip-validate-spec

Steps to reproduce

Run the above command with the included yaml
Notice that the following expected line is missing:
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';

Suggest a fix

multipartFormData mustache is used without vendorExtensions so it's not detected

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 by running the provided openapi-generator command with the YAML example and inspect the generated typescript-axios multipart request. Then trace how the multipartFormData mustache template is used without vendorExtensions. Done means the generated request includes localVarHeaderParameter['Content-Type'] = 'multipart/form-data'; for multipart requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, 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.