11import pytest
22from sqlmodel import Field , SQLModel
3- from sqlmodel ._compat import IS_PYDANTIC_V2
4-
5- from tests .conftest import needs_pydanticv2
63
74
85def test_json_schema_extra_applied ():
@@ -16,11 +13,7 @@ class Item(SQLModel):
1613 }
1714 )
1815
19- if IS_PYDANTIC_V2 :
20- schema = Item .model_json_schema ()
21- else :
22- schema = Item .schema ()
23-
16+ schema = Item .model_json_schema ()
2417 name_schema = schema ["properties" ]["name" ]
2518
2619 assert name_schema ["example" ] == "Sword of Power"
@@ -53,28 +46,20 @@ class LegacyItem(SQLModel):
5346 }
5447 )
5548
56- if IS_PYDANTIC_V2 :
57- schema = LegacyItem .model_json_schema ()
58- else :
59- schema = LegacyItem .schema ()
60-
49+ schema = LegacyItem .model_json_schema ()
6150 name_schema = schema ["properties" ]["name" ]
6251
6352 assert name_schema ["example" ] == "Sword of Old"
6453 assert name_schema ["x-custom-key" ] == "Important Data"
6554
66- if IS_PYDANTIC_V2 :
67- # With Pydantic V1 serialization_alias from schema_extra is applied
68- field_info = LegacyItem .model_fields ["name" ]
69- assert field_info .serialization_alias == "id_test"
70- else : # With Pydantic V1 it just goes to schema
71- assert name_schema ["serialization_alias" ] == "id_test"
55+ # With Pydantic V1 serialization_alias from schema_extra is applied
56+ field_info = LegacyItem .model_fields ["name" ]
57+ assert field_info .serialization_alias == "id_test"
7258
7359
74- @needs_pydanticv2
7560def test_json_schema_extra_mix_in_schema_extra ():
7661 """
77- Test workaround when json_schema_extra was passed via schema_extra with Pydantic v2 .
62+ Test workaround when json_schema_extra was passed via schema_extra.
7863 """
7964
8065 with pytest .warns (DeprecationWarning , match = "schema_extra parameter is deprecated" ):
0 commit comments