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
  • #8119
Closed
Open
Issue created Dec 08, 2020 by Administrator@rootContributor

[REQ] [Javascript] Support multiple media types in responses

Created by: phillipuniverse

Is your feature request related to a problem? Please describe.

This is a very similar issue as #440 (closed) but for Javascript. Here is an example endpoint with multiple representations that could be returned (csv or json):

  /endpoint-returning-csv/:
    get:
      responses:
        '200':
          content:
            text/csv:
              schema:
                format: binary
                type: string
          description: Retrieve CSV data
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
            description: Default error response
      summary: Retrieve CSV export
      tags:
      - default

This generates the following API:

endpointReturningCsvGet(opts, callback) {
      opts = opts || {};
      let postBody = null;

      let pathParams = {
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['AuthToken'];
      let contentTypes = [];
      let accepts = ['text/csv', 'application/json'];
      let returnType = File;
      return this.apiClient.callApi(
        '/endpoint-returning-csv/', 'GET',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType, null, callback
      );
    }

This all looks correct. But, the generated apiClient.callApi only ever returns a single mime type, and always application/json if it is included:

https://github.com/OpenAPITools/openapi-generator/blob/99d83712a8c64bdc0b47cb949efd35b99f41d0f6/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache#L185-L198

Describe the solution you'd like

I would like to be able to describe multiple produces parameters with different content types as documented in OpenAPI 3 and all of those be passed to the server. It would be nice to have full deserialization support for all of the different content types like in the Python PR, but at a minimum all content types should be sent in the Accept header.

Describe alternatives you've considered

A workaround for me is to remove the secondary JSON response altogether, leaving only the CSV response. Since I was coming from Swagger 2 codegen anyway that only allowed a single media type, this solution worked for me as a stop-gap.

Additional context

None!

Assignee
Assign to
Time tracking