OpenAPITools / OpenAPITools/openapi-generator

[BUG] array parameters in FormData should not be join to string by csv

Open
#18,506 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

api templates use wrong way to deal with array parameters in form body. for example:
line 165-177 at typescript-rxjs/apis.mustache:

        const formData = new FormData();
        {{#formParams}}
        {{#isArray}}
        if ({{> paramNamePartial}} !== undefined) {
            {{#isCollectionFormatMulti}}
            {{> paramNamePartial}}.forEach((element) => formData.append('{{baseName}}', element as any))
            {{/isCollectionFormatMulti}}
            {{^isCollectionFormatMulti}}
            formData.append('{{baseName}}', {{> paramNamePartial}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
            {{/isCollectionFormatMulti}}
        }

        {{/isArray}}

only if isCollectionFormatMulti is true, the array parameter will be add to FormData as an array, otherwise it will be join to a string.
according to DefaultCodegen::getCollectionFormat, isCollectionFormatMulti is true when style=form and explode=true, BUT "style" and "explode" are not valid for request body parameters.
ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-values
style and explode are for Parameter Object which define parameters in path, query, header or cookie, so you can never set style=form, explode=true for an array parameter in request body(FormData). manually add them will cause a "Schema validation: Property 'style' is not allowed" warning at ide.

openapi-generator version

checked 5.0.0, 6.0.0 and 7.5.0, I think the problem never been fixed at any version

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

remove isCollectionFormatMulti checking code for array parameters in FormData, like this:

        const formData = new FormData();
        {{#formParams}}
        {{#isArray}}
        if ({{> paramNamePartial}} !== undefined) {
            {{> paramNamePartial}}.forEach((element) => formData.append('{{baseName}}', element as any))
        }

        {{/isArray}}

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 in typescript-rxjs/apis.mustache around lines 165-177 and inspect how array form parameters are serialized into FormData. Generate a client from the multipart/form-data schema shown in the issue, then verify that each array element is appended separately rather than joined into one CSV string.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.