Skip to content

Commit 2c6ce31

Browse files
author
gabino
committed
refactor: replace HttpUrl and AnyUrl with cuenca_validations.types
1 parent 5e2c585 commit 2c6ce31

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

cuenca/resources/endpoints.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
from typing import Annotated, ClassVar, List, Optional, cast
1+
from typing import ClassVar, List, Optional, cast
22

3+
from cuenca_validations.types import HttpUrlString
34
from cuenca_validations.types.enums import WebhookEvent
45
from cuenca_validations.types.requests import (
56
EndpointRequest,
67
EndpointUpdateRequest,
78
)
8-
from pydantic import AfterValidator, ConfigDict, Field, HttpUrl
9+
from pydantic import ConfigDict, Field, HttpUrl
910

1011
from ..http import Session, session as global_session
1112
from .base import Creatable, Deactivable, Queryable, Retrievable, Updateable
1213

13-
# In Pydantic v2, URL fields like `HttpUrl` are stored as internal objects
14-
# instead of `str`, which can break compatibility with code expecting str.
15-
# Using `HttpUrlString` ensures the field is validated as a URL but stored as
16-
# a `str` for compatibility.
17-
# https://github.com/pydantic/pydantic/discussions/6395
18-
19-
HttpUrlString = Annotated[HttpUrl, AfterValidator(str)]
20-
2114

2215
class Endpoint(Creatable, Deactivable, Retrievable, Queryable, Updateable):
2316
_resource: ClassVar = 'endpoints'

cuenca/resources/sessions.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import datetime as dt
2-
from typing import Annotated, ClassVar, Optional, cast
2+
from typing import ClassVar, Optional, cast
33

4-
from cuenca_validations.types import SessionRequest, SessionType
5-
from pydantic import AfterValidator, AnyUrl, ConfigDict
4+
from cuenca_validations.types import AnyUrlString, SessionRequest, SessionType
5+
from pydantic import AnyUrl, ConfigDict
66

77
from .. import http
88
from .base import Creatable, Queryable, Retrievable
99

10-
# In Pydantic v2, URL fields like `AnyUrl` are stored as internal objects
11-
# instead of `str`, which can break compatibility with code expecting str.
12-
# Using `AnyUrlString` ensures the field is validated as a URL but stored as
13-
# a `str` for compatibility.
14-
# https://github.com/pydantic/pydantic/discussions/6395
15-
16-
AnyUrlString = Annotated[AnyUrl, AfterValidator(str)]
17-
1810

1911
class Session(Creatable, Retrievable, Queryable):
2012
_resource: ClassVar = 'sessions'

0 commit comments

Comments
 (0)