[typescript-fetch] Preserve nullable primitive oneOf branches
Context
A nullable primitive branch in an OpenAPI 3.0 oneOf loses null in the generated TypeScript type. This affects both the separate-model and withoutRuntimeChecks output modes.
For example:
oneOf:
- type: string
nullable: true
- type: number
The generated declaration is number | string, although this schema also accepts null.
Root cause
The oneOf type-name strings do not retain branch nullability. The corresponding composed-schema properties still contain it.
Decision
Count nullable branches from the composed-schema properties and add null to the generated type union when exactly one branch is nullable. This fixes the type metadata without a template override or a new generator option.
Consequences
Nullable primitive unions include null. Unions with zero or two nullable primitive branches keep their non-null declaration, consistent with the exactly-one matching rule of oneOf. Nullable array elements do not make the array itself nullable.
cc @joscha
Summary by cubic
Fixes the TypeScript fetch generator so nullable primitive oneOf branches preserve null in the generated union type.
- Adds
nullto the union only when exactly one branch is nullable, matching theoneOfsemantics. - Nullable array items don't make the containing array itself nullable.