Skip to content

Commit 6d4a60e

Browse files
terryykoocopybara-github
authored andcommitted
fix: Set propertyOrdering when schema is specified as dict or types.Schema.
PiperOrigin-RevId: 752296364
1 parent 2b82d72 commit 6d4a60e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

google/genai/_transformers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def t_schema(
790790
if not origin:
791791
return None
792792
if isinstance(origin, dict) and _is_type_dict_str_any(origin):
793-
process_schema(origin, client, order_properties=False)
793+
process_schema(origin, client)
794794
return types.Schema.model_validate(origin)
795795
if isinstance(origin, EnumMeta):
796796
return _process_enum(origin, client)
@@ -799,7 +799,7 @@ def t_schema(
799799
# response_schema value was coerced to an empty Schema instance because it did not adhere to the Schema field annotation
800800
raise ValueError(f'Unsupported schema type.')
801801
schema = origin.model_dump(exclude_unset=True)
802-
process_schema(schema, client, order_properties=False)
802+
process_schema(schema, client)
803803
return types.Schema.model_validate(schema)
804804

805805
if (

google/genai/tests/transformers/test_schema.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,25 @@ def test_t_schema_does_not_change_property_ordering_if_set(client):
605605
assert transformed_schema.property_ordering == custom_property_ordering
606606

607607

608-
def test_t_schema_does_not_set_property_ordering_for_json_schema(client):
609-
"""Tests t_schema doesn't set the property_ordering field for json schemas."""
608+
def test_t_schema_sets_property_ordering_for_json_schema(client):
609+
"""Tests t_schema sets the property_ordering field for json schemas."""
610610

611611
schema = CountryInfo.model_json_schema()
612612

613613
transformed_schema = _transformers.t_schema(client, schema)
614-
assert transformed_schema.property_ordering is None
614+
assert transformed_schema.property_ordering == [
615+
'name',
616+
'population',
617+
'capital',
618+
'continent',
619+
'gdp',
620+
'official_language',
621+
'total_area_sq_mi',
622+
]
615623

616624

617-
def test_t_schema_does_not_set_property_ordering_for_schema_type(client):
618-
"""Tests t_schema doesn't set the property_ordering field for Schema types."""
625+
def test_t_schema_sets_property_ordering_for_schema_type(client):
626+
"""Tests t_schema sets the property_ordering field for Schema types."""
619627

620628
schema = types.Schema(
621629
properties={
@@ -635,4 +643,4 @@ def test_t_schema_does_not_set_property_ordering_for_schema_type(client):
635643
)
636644

637645
transformed_schema = _transformers.t_schema(client, schema)
638-
assert transformed_schema.property_ordering is None
646+
assert transformed_schema.property_ordering == ['name', 'population']

0 commit comments

Comments
 (0)