googleapis / googleapis/python-genai

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

Aperta
#1,992 6 commenti 0 reazioni 1 assegnatario Rivendicata da @Venkaiahbabuneelam Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

#### 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!

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.