Uh oh!
There was an error while loading. Please reload this page.
fix: expand $ref references in JSON Schema for Gemini compatibility - #12292
fix: expand $ref references in JSON Schema for Gemini compatibility#12292high726 wants to merge 1 commit into
Conversation
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
The following comment was made by an LLM, it may be inaccurate: Potential Related PR FoundPR #11968 - "fix: apply schema transformation to MCP tools for Gemini compatibility" Why it's related: According to the PR description (line 53), PR #11968 applies schema transformation to MCP tools and is directly complementary to this PR. The current PR (#12292) handles This appears to be the primary related PR. The other results are either the current PR itself or unrelated changes. |
Gemini API rejects schemas with $ref alongside other fields, causing errors like:
"$ref 'QuestionOption' was set alongside unsupported fields"
This fix adds $ref expansion before sending schemas to Gemini:
- Expands $ref references by inlining definitions from $defs/definitions
- Handles nested $ref references recursively
- Protects against circular references by returning { type: 'object' }
- Preserves additional fields (like description) when expanding
- Removes $defs/definitions after expansion
Related issues:
- google-gemini/gemini-cli#13326
- anomalyco#5832
- anomalyco#8417508f84e to
7ad4a99CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Summary
Gemini API rejects schemas containing
$refalongside other fields, causing errors like:This fix adds
$refexpansion inProviderTransform.schema()before sending schemas to Gemini.Fixes#12295
Changes
$refreferences by inlining definitions from$defs/definitions$refreferences recursively{ type: "object" }description) when expanding$defs/definitionsafter expansionFiles Changed
packages/opencode/src/provider/transform.tsexpandRefs()function beforesanitizeGemini()packages/opencode/test/provider/transform.test.ts$refexpansionTest Cases
$refwith$defs$refin array items$refreferences$refby returning simple objectdefinitions(legacy format)descriptionwhen expanding$ref$reffor non-Gemini providersRelated Issues
$defsreferencesRelated PRs
$ref)