Skip to content

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

Open
@jharriman

Description

@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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions