← Back to PRs

#20990: fix: Handle single-element type arrays in tryFlattenLiteralAnyOf

by chilu18 open 2026-02-19 14:35 View on GitHub →
agents size: S
## Summary Fixes #20898 `tryFlattenLiteralAnyOf` was failing to flatten unions when schema variants used `type: ["string"]` instead of `type: "string"`, even though both are valid and semantically identical per JSON Schema spec. ## Changes Added `resolveVariantType()` helper function that normalizes type representation: - `type: "string"` → `"string"` - `type: ["string"]` → `"string"` (single-element array) - `type: ["string", "null"]` → `null` (multi-element, bail out) ## Testing Added comprehensive test suite (`src/agents/schema/clean-for-gemini.test.ts`): - ✅ Flattens anyOf with type as string - ✅ Flattens anyOf with type as single-element array - ✅ Flattens mixed string and array types - ✅ Does not flatten when types differ - ✅ Handles multi-element type arrays with null stripping ```bash pnpm test src/agents/schema/clean-for-gemini.test.ts # Test Files 1 passed (1) # Tests 5 passed (5) ``` ## Impact **Low risk** - Only affects schema normalization for Gemini. Existing behavior preserved for all other cases. Closes #20898 <!-- greptile_comment --> <h3>Greptile Summary</h3> Added `resolveVariantType()` helper to normalize type representation in `tryFlattenLiteralAnyOf`, fixing a bug where schemas with `type: ["string"]` (single-element array) were not being flattened even though they're semantically identical to `type: "string"` per JSON Schema spec. - Handles string types, single-element type arrays, and correctly bails on multi-element arrays - Comprehensive test coverage validates the fix for all edge cases - Minimal change with clear focus on the reported issue <h3>Confidence Score: 5/5</h3> - Safe to merge with no risk - The change is minimal, well-tested, and narrowly scoped to fixing a specific schema normalization issue. The helper function correctly handles all edge cases, and comprehensive tests verify the behavior. No breaking changes or side effects. - No files require special attention <sub>Last reviewed commit: 3266004</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs