Skip to content

Commit 079cba5

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#1161)
1 parent 6031ae9 commit 079cba5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 1254
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-21c3f4e3559582f365d9afb16ec8ccfadc79aa7fd5c5d295a3f1bebfa28765ca.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-ca12a5056d3bb298068f1638207e72d7ea56d56fa0fbdcbcdfc1c57f6b253f14.yml

src/cloudflare/_models.py

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ClassVar,
1111
Protocol,
1212
Required,
13+
ParamSpec,
1314
TypedDict,
1415
TypeGuard,
1516
final,
@@ -67,6 +68,9 @@
6768
__all__ = ["BaseModel", "GenericModel"]
6869

6970
_T = TypeVar("_T")
71+
_BaseModelT = TypeVar("_BaseModelT", bound="BaseModel")
72+
73+
P = ParamSpec("P")
7074

7175

7276
@runtime_checkable
@@ -379,6 +383,29 @@ def is_basemodel_type(type_: type) -> TypeGuard[type[BaseModel] | type[GenericMo
379383
return issubclass(origin, BaseModel) or issubclass(origin, GenericModel)
380384

381385

386+
def build(
387+
base_model_cls: Callable[P, _BaseModelT],
388+
*args: P.args,
389+
**kwargs: P.kwargs,
390+
) -> _BaseModelT:
391+
"""Construct a BaseModel class without validation.
392+
393+
This is useful for cases where you need to instantiate a `BaseModel`
394+
from an API response as this provides type-safe params which isn't supported
395+
by helpers like `construct_type()`.
396+
397+
```py
398+
build(MyModel, my_field_a="foo", my_field_b=123)
399+
```
400+
"""
401+
if args:
402+
raise TypeError(
403+
"Received positional arguments which are not supported; Keyword arguments must be used instead",
404+
)
405+
406+
return cast(_BaseModelT, construct_type(type_=base_model_cls, value=kwargs))
407+
408+
382409
def construct_type(*, value: object, type_: object) -> object:
383410
"""Loose coercion to the expected type with construction of nested values.
384411

0 commit comments

Comments
 (0)