Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
BaseModel,
EmailStr,
Field,
Json,
conbytes,
confloat,
conint,
Expand Down Expand Up @@ -82,6 +83,7 @@ class UnsupportedKeywordError(SchemaConversionError):
"binary": conbytes(strict=True),
"password": str,
"path": str,
"json": Json,
}


Expand Down
7 changes: 5 additions & 2 deletions python/packages/autogen-core/tests/test_json_to_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
UnsupportedKeywordError,
_JSONSchemaToPydantic, # pyright: ignore[reportPrivateUsage]
)
from pydantic import BaseModel, EmailStr, Field, ValidationError
from pydantic import BaseModel, EmailStr, Field, Json, ValidationError


# ✅ Define Pydantic models for testing
Expand Down Expand Up @@ -44,6 +44,7 @@ class ComplexModel(BaseModel):
user: User
extra_info: Optional[Dict[str, Any]] = None # Optional dictionary
sub_items: List[Employee] # List of Employees
json_string: Optional[Json[Any]] = None # Optional JSON string


@pytest.fixture
Expand Down Expand Up @@ -82,7 +83,7 @@ def sample_json_schema_complex() -> Dict[str, Any]:
(sample_json_schema, "User", ["id", "name", "email", "age", "address"]),
(sample_json_schema_recursive, "Employee", ["id", "name", "manager"]),
(sample_json_schema_nested, "Department", ["name", "employees"]),
(sample_json_schema_complex, "ComplexModel", ["user", "extra_info", "sub_items"]),
(sample_json_schema_complex, "ComplexModel", ["user", "extra_info", "sub_items", "json_string"]),
],
)
def test_json_schema_to_pydantic(
Expand Down Expand Up @@ -160,6 +161,7 @@ def test_json_schema_to_pydantic(
{"id": str(uuid4()), "name": "Eve"},
{"id": str(uuid4()), "name": "David", "manager": {"id": str(uuid4()), "name": "Frank"}},
],
"json_string": '{"foo": "bar"}',
},
),
],
Expand Down Expand Up @@ -241,6 +243,7 @@ def test_valid_data_model(
{"id": "invalid-uuid", "name": "Eve"}, # Invalid UUID
{"id": str(uuid4()), "name": 123}, # Invalid name type
],
"json_string": '{"foo": "bar"', # Invalid JSON
},
),
],
Expand Down
Loading