OpenAPITools / OpenAPITools/openapi-generator
[Question] How to use id[]=1&id[]=2 when requestBody format is application/x-www-form-urlencoded
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.
- https://swagger.io/docs/specification/v3_0/serialization/
- https://github.com/swagger-api/swagger-ui/issues/4836
I know that options like
styleandexplodein the link above cannot be used inrequestBody.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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