OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-node] Query parameters do not support `explode: false, style: form`
Nobody has claimed this yet.
- 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
CSV array serialization for query parameter is not supported for OAS3. It seems that explode is ignored at all.
openapi-generator version
5.0.1
OpenAPI declaration file content or url
Pet Store API OAS3 with modified listPets that accepts query parameter tags (explode: false, style: form)
- name: tags
in: query
description: Filter by tags
required: false
allowEmptyValue: true
style: form
explode: false
schema:
type: array
items:
type: string
Generation Details
Command:
npx @openapitools/openapi-generator-cli generate \
-i ./petstore.yaml \
-g typescript-node --generate-alias-as-model \
-c ./codegen.config.json \
-o ./generated/
Contents of codegen.config.json:
{
"sortParamsByRequiredFlag": true,
"ensureUniqueParams": true,
"allowUnicodeIdentifiers": false,
"modelPropertyNaming": "camelCase",
"supportsES6": false,
"snapshot": false,
"typescriptThreePlus": true
}
Steps to reproduce
- Generate the code
- Add a debugging console.log statement to
petsApi.ts:L208:console.log(localVarRequest(localVarRequestOptions).uri.query) - Instantiate api and call the method
import { PetsApi } from './generated/api'
const api = new PetsApi()
api.listPets(10, ["dog", "cat"])
- Output will be
limit=10&tags%5B0%5D=dog&tags%5B1%5D=cat
Expected: limit=10&tags=dog,cat
Related issues/PRs
I think this issue is related: https://github.com/OpenAPITools/openapi-generator/issues/7973
Suggest a fix
Not able, but with few advices on which template variables to use and example implementation in other clients I might be able to fix it and send pull request.
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
Reproduce the issue with the provided Pet Store OAS3 declaration and typescript-node generation command. Start at generated petsApi.ts around line 208, then trace the typescript-node request query serialization to see how the tags array is encoded. Done means explode:false with style:form produces tags=dog,cat instead of indexed tags parameters, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100