Skip to content

Commit

Permalink
refactor: replace HttpUrl and AnyUrl with cuenca_validations.types
Browse files Browse the repository at this point in the history
  • Loading branch information
gabino committed Jan 9, 2025
1 parent 5e2c585 commit 2c6ce31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
13 changes: 3 additions & 10 deletions cuenca/resources/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
from typing import Annotated, ClassVar, List, Optional, cast
from typing import ClassVar, List, Optional, cast

from cuenca_validations.types import HttpUrlString
from cuenca_validations.types.enums import WebhookEvent
from cuenca_validations.types.requests import (
EndpointRequest,
EndpointUpdateRequest,
)
from pydantic import AfterValidator, ConfigDict, Field, HttpUrl
from pydantic import ConfigDict, Field, HttpUrl

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

# In Pydantic v2, URL fields like `HttpUrl` are stored as internal objects
# instead of `str`, which can break compatibility with code expecting str.
# Using `HttpUrlString` ensures the field is validated as a URL but stored as
# a `str` for compatibility.
# https://github.com/pydantic/pydantic/discussions/6395

HttpUrlString = Annotated[HttpUrl, AfterValidator(str)]


class Endpoint(Creatable, Deactivable, Retrievable, Queryable, Updateable):
_resource: ClassVar = 'endpoints'
Expand Down
14 changes: 3 additions & 11 deletions cuenca/resources/sessions.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import datetime as dt
from typing import Annotated, ClassVar, Optional, cast
from typing import ClassVar, Optional, cast

from cuenca_validations.types import SessionRequest, SessionType
from pydantic import AfterValidator, AnyUrl, ConfigDict
from cuenca_validations.types import AnyUrlString, SessionRequest, SessionType
from pydantic import AnyUrl, ConfigDict

from .. import http
from .base import Creatable, Queryable, Retrievable

# In Pydantic v2, URL fields like `AnyUrl` are stored as internal objects
# instead of `str`, which can break compatibility with code expecting str.
# Using `AnyUrlString` ensures the field is validated as a URL but stored as
# a `str` for compatibility.
# https://github.com/pydantic/pydantic/discussions/6395

AnyUrlString = Annotated[AnyUrl, AfterValidator(str)]


class Session(Creatable, Retrievable, Queryable):
_resource: ClassVar = 'sessions'
Expand Down

0 comments on commit 2c6ce31

Please sign in to comment.