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
  • #3990
Closed
Open
Issue created Sep 30, 2019 by Administrator@rootContributor

[REQ] Allow multiple bodyParams for multiple Content Types in RequestBody

Created by: jharriman

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

The requestBody specification for OpenAPI 3.0 (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#requestBodyObject) allows you to specify multiple MediaType names and schemas for the Content section of the requestBody.

Leveraging the ability to use multiple MediaTypes in the Content section of the requestBody is quite helpful when your MediaTypes are more meaningful than application/json e.g.

    put:
      operationId: updatePet
      requestBody:
        content:
          application/vnd.petstore.pet.v1+json:
            schema:
              $ref: '#/components/schemas/PetV1'
          application/vnd.petstore.pet.v2+json:
            schema:
              $ref: '#/components/schemas/PetV2'

Unfortunately, the current implementation of openapi-generator assumes that you will only ever specify one MediaType in you content definition:

  • In the fromRequestBody method of DefaultCodegen (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L4776) only the a single CodegenParameter is returned.
  • Looking deeper in the stack, it looks like ModelUtils.getSchemaFromRequestBody and ModelUtils.getSchemaFromContent (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java#L766) assume that there will only ever be one MediaType. At least an warning is printed letting you know that something is wrong, but that's still unhelpful when you actually want to support multiple MediaTypes in the Content section.

Describe the solution you'd like

It looks like the DefaultCodegen class is already setup to support multiple bodyParams, but the current implementation only ever adds one bodyParam to the list.

Specifically the following changes should be made

  • Parse all possible Content MediaTypes as bodyParams and return a list of CodegenParameter for fromRequestBody
  • Add a new contentType property to the CodegenParameter object to allow generators to know which contentType is associated with each bodyParam

Describe alternatives you've considered

You could alternatively add a property to the consumes object specifying which bodyParam belongs to the listed contentType . . . but that’s means you’d also have to add an identifier to each bodyParam anyway.

Assignee
Assign to
Time tracking