OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.51k stars 6.27k forks source link

[BUG][typescript-axios] Schema with `oneOf` is processed incorrectly #18999

Open turtton opened 6 days ago

turtton commented 6 days ago

Bug Report Checklist

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
  1. clone https://github.com/turtton/openapi-generator-bug-reproduction
  2. run ./gen-latest and see generated-latest/api.ts or corepack enable && pnpm i && pnpm openapi-generator-cli generate and see generated76/api.ts
Related issues/PRs

17335

16898

Suggest a fix