fix(typescript-fetch): skip scalar enum comparison for array-typed properties in instanceOf
Required properties typed as Array<SingleValueEnum> triggered two bugs in the instanceOf guard (side effect of #23497):
- The enum-literal check fired for array properties — comparing
value['types'] !== 'x'against an array is always truthy, permanently breakinginstanceOf. - For array properties,
isStringresolves against the container type (Array), not the item type, so the literal was emitted unquoted (boatbooker_activitiesinstead of'boatbooker_activities'), causingTS2304: Cannot find name.
Fix: wrap the enum-literal block in {{^isContainer}} so it only fires for scalar properties. Scalar enum behavior is unchanged.
Apologies for the burst of PRs in a short time — we are integrating this generator into production at FishingBooker and kept uncovering issues along the way.
Also sorry for skipping a prior issue on this one; if a release is coming soon we'd love to see it included. Happy to open a follow-up issue if preferred.
Fixes a regression introduced by #23497.
PR checklist
- Read the contribution guidelines.
- Ran unit tests:
./mvnw test -pl modules/openapi-generator -Dtest=TypeScriptFetchClientCodegenTest - Regenerated typescript-fetch samples:
./bin/generate-samples.sh ./bin/configs/typescript-fetch* - @mention the technical committee members.
cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @dennisameling
Summary by cubic
Fixes the instanceOf guard in typescript-fetch to skip scalar enum comparisons for array-typed enum properties (e.g., Array<SingleValueEnum>), preventing false negatives and TypeScript literal name errors. Scalar enum behavior is unchanged.
- Bug Fixes
- Wrapped the enum-literal check with
{{^isContainer}}inmodelGeneric.mustacheso array enums no longer emit invalid!==comparisons or unquoted literals. - Added a test (
testInstanceOfArrayEnumNoScalarComparison) with a minimal OpenAPI fixture to verify no scalar comparison is emitted and the field presence check remains.
- Wrapped the enum-literal check with