googleapis / googleapis/python-genai
Schema.from_json_schema() loses description and title when unwrapping nullable any_of schemas
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
#### Environment details
- Programming language: python
- OS: macOS
- Language runtime version: 3.13.2
- Package version: 1.53.0
#### Steps to reproduce
```python
from google.genai.types import JSONSchema, Schema
json_schema = JSONSchema(
any_of=[
JSONSchema(type='string'),
JSONSchema(type='null'),
],
description='xxx',
title='xxx'
)
schema = Schema.from_json_schema(json_schema=json_schema)
print(schema.description) # Expected: 'xxx' | Actual: None
print(schema.nullable) # True (correct)
```
## Actual Behavior
The `description` and `title` are lost. Only `nullable=True` and the type information are preserved.
### Root Cause
In `types.py`, the unwrap logic at lines 2706-2712 replaces the entire schema with `type_part` but only carries over the `default` value:
```python
if nullable_part and type_part:
default_value = schema.default
schema = type_part # <-- Loses description, title, and other fields
schema.nullable = True
if default_value is not None:
schema.default = default_value
```
### Suggest Fix
```python
if nullable_part and type_part:
default_value = schema.default
description_value = schema.description
title_value = schema.title
schema = type_part
schema.nullable = True
if default_value is not None:
schema.default = default_value
if description_value is not None:
schema.description = description_value
if title_value is not None:
schema.title = title_value
```
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.