Repository navigation
fix(tools): resolve JSON Pointer $ref in _dereference_schema - #6148
foivos-all wants to merge 3 commits into
Conversation
|
Hi @foivos-all , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit test and fix formatting errors before we can proceed with a review. |
83039fc to
1351700
Compare
|
Hi @rohityan, I fixed the failing pre-commit checks. Let me know if you can proceed with a review |
|
@rohityan I believe the unit test that is failing is broken. It's failing because in |
Merge #6148 PiperOrigin-RevId: 1000455580
|
Thank you @foivos-all for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 59fe93b. Closing this PR as the changes are now in the main branch. |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
RecursionErrorin_to_gemini_schema()when processing circular$refin$defs#38702. Or, if no issue exists, describe the change:
Problem:
_dereference_schemacurrently resolves$refby looking up the last path segment in$defs/definitions. However, JSON Schema$refcan also use JSON Pointer syntax pointing to arbitrary paths within the document (e.g.,"$ref": "#/properties/address"refers to a sibling property). These references are silently left unresolved (returned as-is), which can cause a downstreamKeyErroror schema conversion failures when the unreferenced$refkeyword leaks into the Gemini schema validator.Solution:
Added a
_resolve_json_pointerhelper inside_dereference_schemathat navigates the schema tree following the JSON Pointer path. When the existing$defs/definitionslookup fails, the code now attempts JSON Pointer resolution before falling back to returning the$refas-is. The helper handles:#/properties/foo/properties/bar)#/properties/items/0)~1→/,~0→~)path_refstracking)Testing Plan
Unit Tests:
I have added or updated unit tests for my change.
All unit tests pass locally.
test_json_pointer_ref: resolves a sibling JSON Pointer#/properties/btest_circular_json_pointer_ref: mutual circular JSON Pointer refstest_json_pointer_to_array_element: JSON Pointer to an array element via_dereference_schemaAll 72 tests in
test_gemini_schema_util.pypass.Manual End-to-End (E2E) Tests:
A JSON Pointer
$reflike#/properties/brefers to a sibling property within the same schema. On main, this is left unresolved. Run the following:BEFORE (
main) -$refis NOT resolved:AFTER (
fix/json-pointer-refs) -$refis resolvedChecklist
Additional context
This comment on #3880 (comment) is from a reviewer:
