OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] Schema with `oneOf` is processed incorrectly
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
When using oneOf to represent a tuple, the process of inserting the value as a query is incorrect.
Please see this repository:
https://github.com/turtton/openapi-generator-bug-reproduction
openapi-generator version
7.6.0
OpenAPI declaration file content or url
components:
schemas:
Id:
type: integer
format: int32
CreatedAt:
type: string
format: date-time
Cursor:
oneOf:
- $ref: '#/components/schemas/Id'
- $ref: '#/components/schemas/CreatedAt'
Full code
https://github.com/turtton/openapi-generator-bug-reproduction/blob/main/api.yaml
Generation Details
Type
export type Cursor = number | string;
if (cursor !== undefined) {
for (const [key, value] of Object.entries(cursor)) { // Object.entries always returns empty array
localVarQueryParameter[key] = value;
}
}
expected(~7.0.0):
if (cursor !== undefined) {
localVarQueryParameter['cursor'] = cursor;
}
Steps to reproduce
- clone https://github.com/turtton/openapi-generator-bug-reproduction
- run
./gen-latestand seegenerated-latest/api.ts
orcorepack enable && pnpm i && pnpm openapi-generator-cli generateand seegenerated76/api.ts
Related issues/PRs
#17335
#16898
Suggest a fix
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 reproduction repository, api.yaml, and the generated-latest/api.ts or generated76/api.ts files; run ./gen-latest or the documented pnpm command to compare the output. Trace the typescript-axios generation path for the cursor query parameter. Done means a oneOf value is assigned to the cursor query key rather than iterated with Object.entries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100