Skip to content

fix: preserve schema metadata for nullable anyOf - #2917

Open
mikemikimike wants to merge 2 commits into
googleapis:mainfrom
mikemikimike:fix/1992-preserve-schema-metadata
Open

fix: preserve schema metadata for nullable anyOf#2917
mikemikimike wants to merge 2 commits into
googleapis:mainfrom
mikemikimike:fix/1992-preserve-schema-metadata

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Aug 27, 2026

Copy link
Copy Markdown

Summary

Fixes #1992.

Schema.from_json_schema() dropped the parent schema's description and title
when unwrapping a two-part nullable any_of schema. This caused schema metadata
to be lost for callers using this JSON Schema form.

Changes

  • Preserve description and title when a nullable any_of schema is unwrapped
    into its non-null type schema.
  • Add a regression test covering both the Gemini API and Vertex AI conversion
    paths.

Compatibility

This is an internal conversion fix. It does not change the public API surface or
the existing handling of type, nullable, or default.

Tests

  • .venv\\Scripts\\python.exe -m pytest google/genai/tests/types/test_schema_from_json_schema.py -q10 passed.
  • .venv\\Scripts\\python.exe -m pytest google/genai/tests/types -q181 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.
  • Ruff selected-rule check — the five reported diagnostics match the base commit exactly; none are on changed lines. Ruff is not configured by this repository.

Not run

  • google/genai/tests/imports/test_no_optional_imports.py was invoked but skipped because it only runs on GitHub Actions.
  • The full network-backed test suite was not run because this regression is covered by offline unit tests and does not require credentials or external services.

Remote verification

  • PR fix: preserve schema metadata for nullable anyOf #2917 targets googleapis/python-genai:main from mikemikimike/python-genai:fix/1992-preserve-schema-metadata.
  • The remote head 85e9f0391a9d9a5e616c5d4c4abfb25e6e61c781 matches the locally verified commit.
  • GitHub reports the PR as mergeable; 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.

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Aug 28, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:M Code changes between 10-40 lines label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M Code changes between 10-40 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema.from_json_schema() loses description and title when unwrapping nullable any_of schemas

2 participants