OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-fetch] oneOf ToJSON applies the date variant's toISOString() to every variant

Open
#24,321 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

typescript-fetch, generator 7.14.0. A oneOf model where one variant has format: date-time properties and the others don't generates a ...ToJSONTyped that calls .toISOString() on the shared property names unconditionally. Serializing the number or string variant crashes with .toISOString is not a function. The generated discriminator type also collapses to the date variant's literal instead of the union.

Repro
components:
  schemas:
    Value:
      oneOf:
        - $ref: '#/components/schemas/NumberValue'
        - $ref: '#/components/schemas/DateValue'
    NumberValue:
      type: object
      required: [kind, value]
      properties:
        kind: { type: string, enum: [Number] }
        value: { type: number }
    DateValue:
      type: object
      required: [kind, value]
      properties:
        kind: { type: string, enum: [Date] }
        value: { type: string, format: date-time }

ValueToJSON({ kind: 'Number', value: 4 }) throws. Expected: dispatch per variant, or at least guard the Date conversion.

Generation Details

typescript-fetch, openapi-generator 7.14.0, spec produced by @typespec/openapi3.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the typescript-fetch client from the YAML reproduction and inspect the generated ValueToJSON and ValueToJSONTyped functions. Trace how the oneOf variants and shared value property are serialized; done means NumberValue no longer calls toISOString(), DateValue still serializes its date, and the discriminator type preserves the union.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.