|
11 | 11 | UnsupportedKeywordError, |
12 | 12 | _JSONSchemaToPydantic, # pyright: ignore[reportPrivateUsage] |
13 | 13 | ) |
14 | | -from pydantic import BaseModel, EmailStr, Field, ValidationError |
| 14 | +from pydantic import BaseModel, EmailStr, Field, Json, ValidationError |
15 | 15 |
|
16 | 16 |
|
17 | 17 | # ✅ Define Pydantic models for testing |
@@ -44,6 +44,7 @@ class ComplexModel(BaseModel): |
44 | 44 | user: User |
45 | 45 | extra_info: Optional[Dict[str, Any]] = None # Optional dictionary |
46 | 46 | sub_items: List[Employee] # List of Employees |
| 47 | + json_string: Optional[Json[Any]] = None # Optional JSON string |
47 | 48 |
|
48 | 49 |
|
49 | 50 | @pytest.fixture |
@@ -82,7 +83,7 @@ def sample_json_schema_complex() -> Dict[str, Any]: |
82 | 83 | (sample_json_schema, "User", ["id", "name", "email", "age", "address"]), |
83 | 84 | (sample_json_schema_recursive, "Employee", ["id", "name", "manager"]), |
84 | 85 | (sample_json_schema_nested, "Department", ["name", "employees"]), |
85 | | - (sample_json_schema_complex, "ComplexModel", ["user", "extra_info", "sub_items"]), |
| 86 | + (sample_json_schema_complex, "ComplexModel", ["user", "extra_info", "sub_items", "json_string"]), |
86 | 87 | ], |
87 | 88 | ) |
88 | 89 | def test_json_schema_to_pydantic( |
@@ -160,6 +161,7 @@ def test_json_schema_to_pydantic( |
160 | 161 | {"id": str(uuid4()), "name": "Eve"}, |
161 | 162 | {"id": str(uuid4()), "name": "David", "manager": {"id": str(uuid4()), "name": "Frank"}}, |
162 | 163 | ], |
| 164 | + "json_string": '{"foo": "bar"}', |
163 | 165 | }, |
164 | 166 | ), |
165 | 167 | ], |
@@ -241,6 +243,7 @@ def test_valid_data_model( |
241 | 243 | {"id": "invalid-uuid", "name": "Eve"}, # Invalid UUID |
242 | 244 | {"id": str(uuid4()), "name": 123}, # Invalid name type |
243 | 245 | ], |
| 246 | + "json_string": '{"foo": "bar"', # Invalid JSON |
244 | 247 | }, |
245 | 248 | ), |
246 | 249 | ], |
|
0 commit comments