Skip to content

Commit dc64d90

Browse files
committed
Use compat layer for pydantic 1
1 parent 14a8501 commit dc64d90

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/fastapi_cloud_cli/utils/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
)
1414

1515
import httpx
16-
from pydantic import BaseModel, Field, TypeAdapter, ValidationError
16+
from pydantic import BaseModel, Field, ValidationError
1717
from typing_extensions import Annotated, ParamSpec
1818

1919
from fastapi_cloud_cli import __version__
2020
from fastapi_cloud_cli.config import Settings
2121
from fastapi_cloud_cli.utils.auth import get_auth_token
22+
from fastapi_cloud_cli.utils.pydantic_compat import TypeAdapter
2223

2324
logger = logging.getLogger(__name__)
2425

src/fastapi_cloud_cli/utils/pydantic_compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ def validate_python(self, value: Any) -> T:
6161
from pydantic import parse_obj_as
6262

6363
return parse_obj_as(self.type_, value) # type: ignore[no-any-return, unused-ignore]
64+
65+
def validate_json(self, value: str) -> T:
66+
"""Validate a JSON string against the type."""
67+
if PYDANTIC_V2:
68+
return self._adapter.validate_json(value) # type: ignore[no-any-return, union-attr, unused-ignore]
69+
else:
70+
from pydantic import parse_raw_as
71+
72+
return parse_raw_as(self.type_, value) # type: ignore[no-any-return, unused-ignore]

0 commit comments

Comments
 (0)