OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] Enum parameter with default value is processed incorrectly since 7.1.0
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
Upgrade to 7.1.0 broke handling of enum parameter with default value - instead of passing as primitive value, it is iterated as object now and generates funny URL with query string ?0=d&1=e&2=s&3=c
allOf:
- $ref: "#/components/schemas/SortOrderEnum"
- default: desc
openapi-generator version
7.1.0
OpenAPI declaration file content or url
- schema:
$ref: "#/components/schemas/SortOrderEnum"
required: false
name: score
in: query
- schema:
allOf:
- $ref: "#/components/schemas/SortOrderEnum"
- default: desc
required: false
name: createdAt
in: query
Generates this code:
if (score !== undefined) {
localVarQueryParameter['score'] = score;
}
if (createdAt !== undefined) {
for (const [key, value] of Object.entries(createdAt)) {
localVarQueryParameter[key] = value;
}
}
Previous (correct) code:
if (score !== undefined) {
localVarQueryParameter['score'] = score;
}
if (createdAt !== undefined) {
localVarQueryParameter['createdAt'] = createdAt;
}
Generation Details
npx openapi-generator-cli generate --generator-key xxx
openapitools.json
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.1.0",
"generators": {
"xxx": {
"generatorName": "typescript-axios",
"inputSpec": "https://xxx/api/swagger/specification.yaml",
"output": "generated/api/xxx",
"generateAliasAsModel": true
}
}
}
}
Related issues/PRs
Caused by #16898
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 with the typescript-axios generator and the regression introduced by #16898, using the supplied OpenAPI declaration and npx openapi-generator-cli command to reproduce the generated query handling. Compare the output for score and createdAt with the expected snippets, then add or update a regression test so an enum parameter with a default is handled as the named query parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100