[PR #12827] fix(provider): fix property order bug in Gemini numeric enum stringification #14389

Open
opened 2026-02-16 18:19:11 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12827

State: open
Merged: No


What does this PR do?

Fixes a property-order-dependent bug in sanitizeGemini() where numeric enum values could remain with integer/number type instead of being converted to string.

The bug occurs because the function checked result.type while iterating object properties, but if the enum key is processed before the type key (which depends on JSON property order), result.type is undefined at the time of the check. This means:

  • Enum values ARE correctly stringified ([1, 2, 3]["1", "2", "3"])
  • But the type is NOT changed from "integer" to "string", causing Gemini API to reject the schema

The fix moves the type conversion to after all properties are iterated, so it works regardless of property order. This is relevant for schemas from MCP tools and plugins where property order in JSON is not guaranteed.

Also adds comprehensive test coverage for numeric enum stringification (7 new tests), which was previously untested.

Fixes #12784

How did you verify your code works?

  • All 105 transform tests pass (including 7 new tests for enum stringification)
  • Full typecheck passes across all 12 packages
  • Tested both property orders: { type, enum } and { enum, type } — both now produce correct output
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12827 **State:** open **Merged:** No --- ### What does this PR do? Fixes a property-order-dependent bug in `sanitizeGemini()` where numeric enum values could remain with `integer`/`number` type instead of being converted to `string`. The bug occurs because the function checked `result.type` while iterating object properties, but if the `enum` key is processed before the `type` key (which depends on JSON property order), `result.type` is `undefined` at the time of the check. This means: - Enum values ARE correctly stringified (`[1, 2, 3]` → `["1", "2", "3"]`) - But the type is NOT changed from `"integer"` to `"string"`, causing Gemini API to reject the schema The fix moves the type conversion to after all properties are iterated, so it works regardless of property order. This is relevant for schemas from MCP tools and plugins where property order in JSON is not guaranteed. Also adds comprehensive test coverage for numeric enum stringification (7 new tests), which was previously untested. Fixes #12784 ### How did you verify your code works? - All 105 transform tests pass (including 7 new tests for enum stringification) - Full typecheck passes across all 12 packages - Tested both property orders: `{ type, enum }` and `{ enum, type }` — both now produce correct output
yindo added the pull-request label 2026-02-16 18:19:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14389