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.
Description
typescript-fetch, generator 7.14.0. A
oneOfmodel where one variant hasformat: date-timeproperties and the others don't generates a...ToJSONTypedthat 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
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.