diff --git a/api.md b/api.md index 89157bead09..40f7e23ef80 100644 --- a/api.md +++ b/api.md @@ -4167,7 +4167,7 @@ Methods: Types: ```python -from cloudflare.types.request_tracers import RequestTracerTrace, TraceCreateResponse +from cloudflare.types.request_tracers import Trace, TraceCreateResponse ``` Methods: diff --git a/src/cloudflare/pagination.py b/src/cloudflare/pagination.py index 5f6aecf9f92..7382cf23d68 100644 --- a/src/cloudflare/pagination.py +++ b/src/cloudflare/pagination.py @@ -1,8 +1,11 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Generic, TypeVar, Optional, cast +from typing import Any, List, Type, Generic, Mapping, TypeVar, Optional, cast from typing_extensions import override +from httpx import Response + +from ._utils import is_mapping from ._models import BaseModel, GenericModel from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage @@ -24,6 +27,8 @@ "AsyncSinglePage", ] +_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel) + _T = TypeVar("_T") @@ -269,6 +274,15 @@ def next_page_info(self) -> None: """ return None + @classmethod + def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003 + return cls.construct( + None, + **{ + **(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}), + }, + ) + class AsyncSinglePage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]): items: List[_T] @@ -287,3 +301,12 @@ def next_page_info(self) -> None: so there will never be a next page. """ return None + + @classmethod + def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003 + return cls.construct( + None, + **{ + **(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}), + }, + ) diff --git a/src/cloudflare/types/request_tracers/__init__.py b/src/cloudflare/types/request_tracers/__init__.py index fb3abea3227..a1d489d78fa 100644 --- a/src/cloudflare/types/request_tracers/__init__.py +++ b/src/cloudflare/types/request_tracers/__init__.py @@ -2,6 +2,6 @@ from __future__ import annotations +from .trace import Trace as Trace from .trace_create_params import TraceCreateParams as TraceCreateParams -from .request_tracer_trace import RequestTracerTrace as RequestTracerTrace from .trace_create_response import TraceCreateResponse as TraceCreateResponse diff --git a/src/cloudflare/types/request_tracers/request_tracer_trace.py b/src/cloudflare/types/request_tracers/trace.py similarity index 78% rename from src/cloudflare/types/request_tracers/request_tracer_trace.py rename to src/cloudflare/types/request_tracers/trace.py index e98038cc66d..32e14ff128c 100644 --- a/src/cloudflare/types/request_tracers/request_tracer_trace.py +++ b/src/cloudflare/types/request_tracers/trace.py @@ -7,10 +7,10 @@ from ..._compat import PYDANTIC_V2 from ..._models import BaseModel -__all__ = ["RequestTracerTrace", "RequestTracerTraceItem"] +__all__ = ["Trace", "TraceItem"] -class RequestTracerTraceItem(BaseModel): +class TraceItem(BaseModel): action: Optional[str] = None """If step type is rule, then action performed by this rule""" @@ -35,15 +35,15 @@ class RequestTracerTraceItem(BaseModel): step_name: Optional[str] = None """Tracing step identifying name""" - trace: Optional[RequestTracerTrace] = None + trace: Optional[Trace] = None type: Optional[str] = None """Tracing step type""" -RequestTracerTrace = List[RequestTracerTraceItem] +Trace = List[TraceItem] if PYDANTIC_V2: - RequestTracerTraceItem.model_rebuild() + TraceItem.model_rebuild() else: - RequestTracerTraceItem.update_forward_refs() # type: ignore + TraceItem.update_forward_refs() # type: ignore diff --git a/src/cloudflare/types/request_tracers/trace_create_response.py b/src/cloudflare/types/request_tracers/trace_create_response.py index 2738569266b..3e72c080e9a 100644 --- a/src/cloudflare/types/request_tracers/trace_create_response.py +++ b/src/cloudflare/types/request_tracers/trace_create_response.py @@ -14,10 +14,10 @@ class TraceCreateResponse(BaseModel): status_code: Optional[int] = None """HTTP Status code of zone response""" - trace: Optional["RequestTracerTrace"] = None + trace: Optional["Trace"] = None -from .request_tracer_trace import RequestTracerTrace +from .trace import Trace if PYDANTIC_V2: TraceCreateResponse.model_rebuild()