OpenAPITools / OpenAPITools/openapi-generator

[Question] How to use id[]=1&id[]=2 when requestBody format is application/x-www-form-urlencoded

Open
#19,766 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

When the requestBody format is application/x-www-form-urlencoded, the server receives an array of ids as follows:

id[]=1&id[]=2
curl --location 'http://localhost/api/users' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'id%5B%5D=1' \
--data-urlencode 'id%5B%5D=2'

openapi-generator-cli command simply:

npx @openapitools/openapi-generator-cli generate -g typescript-axios

But, it is automatically changed as follows

id[]=1,2
localVarFormParams.set('id[]', id.join(base_1.COLLECTION_FORMATS.csv));

So I commented out the generated code and wrote it like this:

// localVarFormParams.set('id[]', id.join(base_1.COLLECTION_FORMATS.csv));
id.forEach(id => localVarFormParams.append('id[]', id));

But if it is converted like this, the server cannot interpret it.

So, I want to know if there is an option to send it as I want.

I know that options like style and explode in the link above cannot be used in requestBody.

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 at the generated typescript-axios form-parameter serialization shown in the issue and trace how application/x-www-form-urlencoded arrays are represented. Reproduce the id[]=1&id[]=2 case from the issue, then verify that the generated output preserves repeated fields rather than comma-joining them.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.