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
  • #3776
Closed
Open
Issue created Aug 28, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][TypeScript] Multipart request missing Content-Type for models

Created by: eirikandre

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Multipart requests are missing Content-Type for json parts. Without this servers like Java/Jersey will not be able to understand the request and the part will be set to null.

The multipart request body should look like this:

-----------------------------4577985812131849638818726930
Content-Disposition: form-data; name="my-thing"; filename="blob"
Content-Type: application/json            <-------------- The missing part

{"foo":"bar"}
-----------------------------4577985812131849638818726930
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: application/octet-stream

<the file content>
-----------------------------4577985812131849638818726930--
openapi-generator version

4.1.1

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  title: My Title
  version: '1'
paths:
  /test:
    post:
      operationId: postMultipart
      summary: Legg til nytt vedlegg
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                my-object:
                  $ref: "#/components/schemas/MyObject"
                file:
                  type: string
                  format: binary
      responses:
        200:
          description: 200 response when everything is ok
components:
  schemas:
    MyObject:
      type: object
      properties:
        foo:
          type: string
Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i test.yaml -g org.openapitools.codegen.languages.TypeScriptAngularClientCodegen

Steps to reproduce
  • Build angular code
  • Open generated angular service
  • find the following code snippet:
 if (my-object !== undefined) {
                formParams = formParams.append('my-object', useForm ? JSON.stringify(vedlegg) : <any>my-object) as any || formParams;
                    }

Instead of JSON.stringify(vedlegg), it should have been wrapped in a new Blob to set Content-Type: new Blob([JSON.stringify(vedlegg)], {type: 'application/json'})

Related issues/PRs

#2733 (closed)

Suggest a fix

Wrap JSON.stringify in Blob:

{{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', {{^isModel}}<any>{{paramName}}{{/isModel}}{{#isModel}}useForm ? new Blob([JSON.stringify({{paramName}})], {type: 'application/json'}) : <any>{{paramName}}{{/isModel}}){{#useHttpClient}} as any || formParams{{/useHttpClient}};

https://github.com/eirikandre/openapi-generator/blob/a22e0fb6bfa6ef6208bab58d2bc18087322f3246/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache#L345

Assignee
Assign to
Time tracking