Skip to content

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

Description

@mvhenten
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions