OpenAPITools / OpenAPITools/openapi-generator

[BUG][core] collectionFormat used for request body parameters

Open
#2,157 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: General Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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?
Description

OAS3 specifies collectionFormat that is useful for serializing collection parameters into places where collections need to be serialized, like in query, header, cookie parameters or path parameters. But it does not mention using collectionFormat for parameters that are somewhere else, for example as a request body.

But openapi-generator provides a collectionFormat value, including for parameters that are not query/header/path/cookie.
This means if we want to pass an array as a JSON in the body, for example, the only workaround is to declare that parameter as not array but string, and force the clients to pass us a json string instead of an array.

openapi-generator version

latest master 2593d78ce6676003293267c992f7a6653aaa6a6b

OpenAPI declaration file content or url
  /endpoint:
    post:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                values:
                  type: array
                  items:
                    type: string
                  description: list of values
Related issues/PRs

#2125 is close, but for path parameters

Suggest a fix

the collectionFormat field for CodegenParameter should stay null in case of body parameters

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how requestBody schemas become CodegenParameter values, especially where collectionFormat is assigned for the multipart/form-data example. Reproduce the issue from the supplied OpenAPI declaration and add a regression test; done means collectionFormat remains null for body parameters while collection parameters retain their supported formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.