fix: preserve schema metadata for nullable anyOf - #2917
Conversation
CAOShurong
left a comment
There was a problem hiding this comment.
Reviewed exact head 2022029. The nullable two-branch anyOf expansion now preserves parent description/title while retaining the expanded type and nullable fields, including the schema shape Pydantic v2 emits for Optional fields.
Locally, the focused schema test passed 10/10 and the complete google/genai/tests/types suite passed 181 tests with 6 skipped. Base/head probes reproduced the metadata loss on the base and its preservation here; compileall and diff checking for the two changed files also passed. The public rollup currently exposes repository/CLA/conventional-commit checks, but no unit-test job, so this approval relies on the exact-head local verification above.
I used AI assistance to help inspect the diff and run the verification; I checked the exact code and results before submitting this review.
GitHub did not accept an approval from this account, so this is recorded as a non-blocking exact-head review instead.
Summary
Fixes #1992.
Schema.from_json_schema()dropped the parent schema'sdescriptionandtitlewhen unwrapping a two-part nullable
any_ofschema. This caused schema metadatato be lost for callers using this JSON Schema form.
Changes
descriptionandtitlewhen a nullableany_ofschema is unwrappedinto its non-null type schema.
paths.
Compatibility
This is an internal conversion fix. It does not change the public API surface or
the existing handling of
type,nullable, ordefault.Tests
.venv\\Scripts\\python.exe -m pytest google/genai/tests/types/test_schema_from_json_schema.py -q—10 passed..venv\\Scripts\\python.exe -m pytest google/genai/tests/types -q—181 passed, 6 skipped, 3 warnings..venv\\Scripts\\python.exe -m mypy google/genai/— success for 35 source files..venv\\Scripts\\pyink.exe --pyink --pyink-indentation 2 --line-length 80 --skip-string-normalization --target-version py310 --check --diff google/genai/types.py google/genai/tests/types/test_schema_from_json_schema.py— both files unchanged..venv\\Scripts\\python.exe -m compileall -q google/genai— passed.git diff --check— passed.Not run
google/genai/tests/imports/test_no_optional_imports.pywas invoked but skipped because it only runs on GitHub Actions.Remote verification
googleapis/python-genai:mainfrommikemikimike/python-genai:fix/1992-preserve-schema-metadata.85e9f0391a9d9a5e616c5d4c4abfb25e6e61c781matches the locally verified commit.check-changes, CLA, and conventional-commit checks pass. The zizmor jobs are skipped, and the current merge state is blocked by repository-side conditions or review requirements.