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
  • #6126
Closed
Open
Issue created May 01, 2020 by Administrator@rootContributor

[REQ] Support Multiple Response Schemas For A Single Endpoint

Created by: BenjaminHetzjelli

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

Our general use case is generating a Java client for our APIs for use in integration tests.

Our issue is a single endpoint, which can conditionally return its data as either plaintext CSV or as our own type in JSON based upon an input parameter. Below is the yaml for describing the responses for this endpoint.

responses:
  "404":
    description: <desc>
  "403":
    description: <desc>
  "401":
    description: <desc>
  "202":
    description: <desc>
  "200":
    description: <desc>
      content:
        text/plain:
          schema:
            type: string
        application/json;charset=utf-8:
          schema:
            type: array
              items:
                $ref: '#/components/schemas/<OurType>'

The behavior that appears is that the generated java method can only return one type (obviously). The type of the generated method changes depending upon which content type is declared first, so the snippet above gives a method that returns String, but reversing the declarations in content results in a method that returns OurType.

Describe the solution you'd like

If possible, allowing the generator to create multiple methods (1 for each response type maybe) for each path could be a solution.

Describe alternatives you've considered

We have considered modifying our Swagger annotations such that the method always returns string, and then do our own deserialisation in our usage of the generated clients.

Additional context

The documentation for OpenAPI 3.0 appears to indicate that defining multiple content types is valid, if not explicitly then by the examples making use of it. https://swagger.io/docs/specification/describing-responses/

Assignee
Assign to
Time tracking