Skip to content

Commit 94c8879

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#1163)
1 parent 4a0644f commit 94c8879

File tree

17 files changed

+139
-43
lines changed

17 files changed

+139
-43
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-d4312bd23a02e20e5d46c142ec08fbe09bb97ce586a900e10d178982734f44ec.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-397336292b6904c10bbe601d75c2153455422a23f3c97a4d6b25087ceab822ad.yml

src/cloudflare/_base_client.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
HttpxSendArgs,
5959
AsyncTransport,
6060
RequestOptions,
61+
HttpxRequestFiles,
6162
ModelBuilderProtocol,
6263
)
6364
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
@@ -459,6 +460,7 @@ def _build_request(
459460
headers = self._build_headers(options)
460461
params = _merge_mappings(self.default_query, options.params)
461462
content_type = headers.get("Content-Type")
463+
files = options.files
462464

463465
# If the given Content-Type header is multipart/form-data then it
464466
# has to be removed so that httpx can generate the header with
@@ -472,14 +474,23 @@ def _build_request(
472474
headers.pop("Content-Type")
473475

474476
# As we are now sending multipart/form-data instead of application/json
475-
# we need to tell httpx to use it, https://www.python-httpx.org/advanced/#multipart-file-encoding
477+
# we need to tell httpx to use it, https://www.python-httpx.org/advanced/clients/#multipart-file-encoding
476478
if json_data:
477479
if not is_dict(json_data):
478480
raise TypeError(
479481
f"Expected query input to be a dictionary for multipart requests but got {type(json_data)} instead."
480482
)
481483
kwargs["data"] = self._serialize_multipartform(json_data)
482484

485+
# httpx determines whether or not to send a "multipart/form-data"
486+
# request based on the truthiness of the "files" argument.
487+
# This gets around that issue by generating a dict value that
488+
# evaluates to true.
489+
#
490+
# https://github.com/encode/httpx/discussions/2399#discussioncomment-3814186
491+
if not files:
492+
files = cast(HttpxRequestFiles, ForceMultipartDict())
493+
483494
# TODO: report this error to httpx
484495
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
485496
headers=headers,
@@ -492,7 +503,7 @@ def _build_request(
492503
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
493504
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
494505
json=json_data,
495-
files=options.files,
506+
files=files,
496507
**kwargs,
497508
)
498509

@@ -1863,6 +1874,11 @@ def make_request_options(
18631874
return options
18641875

18651876

1877+
class ForceMultipartDict(Dict[str, None]):
1878+
def __bool__(self) -> bool:
1879+
return True
1880+
1881+
18661882
class OtherPlatform:
18671883
def __init__(self, name: str) -> None:
18681884
self.name = name

src/cloudflare/resources/addressing/loa_documents/loa_documents.py

+8
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def create(
8080
"""
8181
if not account_id:
8282
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
83+
# It should be noted that the actual Content-Type header that will be
84+
# sent to the server will contain a `boundary` parameter, e.g.
85+
# multipart/form-data; boundary=---abc--
86+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
8387
return self._post(
8488
f"/accounts/{account_id}/addressing/loa_documents",
8589
body=maybe_transform({"loa_document": loa_document}, loa_document_create_params.LOADocumentCreateParams),
@@ -137,6 +141,10 @@ async def create(
137141
"""
138142
if not account_id:
139143
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
144+
# It should be noted that the actual Content-Type header that will be
145+
# sent to the server will contain a `boundary` parameter, e.g.
146+
# multipart/form-data; boundary=---abc--
147+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
140148
return await self._post(
141149
f"/accounts/{account_id}/addressing/loa_documents",
142150
body=await async_maybe_transform(

src/cloudflare/resources/api_gateway/user_schemas/user_schemas.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ def create(
110110
}
111111
)
112112
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
113-
if files:
114-
# It should be noted that the actual Content-Type header that will be
115-
# sent to the server will contain a `boundary` parameter, e.g.
116-
# multipart/form-data; boundary=---abc--
117-
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
113+
# It should be noted that the actual Content-Type header that will be
114+
# sent to the server will contain a `boundary` parameter, e.g.
115+
# multipart/form-data; boundary=---abc--
116+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
118117
return self._post(
119118
f"/zones/{zone_id}/api_gateway/user_schemas",
120119
body=maybe_transform(body, user_schema_create_params.UserSchemaCreateParams),
@@ -392,11 +391,10 @@ async def create(
392391
}
393392
)
394393
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
395-
if files:
396-
# It should be noted that the actual Content-Type header that will be
397-
# sent to the server will contain a `boundary` parameter, e.g.
398-
# multipart/form-data; boundary=---abc--
399-
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
394+
# It should be noted that the actual Content-Type header that will be
395+
# sent to the server will contain a `boundary` parameter, e.g.
396+
# multipart/form-data; boundary=---abc--
397+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
400398
return await self._post(
401399
f"/zones/{zone_id}/api_gateway/user_schemas",
402400
body=await async_maybe_transform(body, user_schema_create_params.UserSchemaCreateParams),

src/cloudflare/resources/dns/records.py

+8
Original file line numberDiff line numberDiff line change
@@ -4326,6 +4326,10 @@ def import_(
43264326
"""
43274327
if not zone_id:
43284328
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
4329+
# It should be noted that the actual Content-Type header that will be
4330+
# sent to the server will contain a `boundary` parameter, e.g.
4331+
# multipart/form-data; boundary=---abc--
4332+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
43294333
return self._post(
43304334
f"/zones/{zone_id}/dns_records/import",
43314335
body=maybe_transform(
@@ -8668,6 +8672,10 @@ async def import_(
86688672
"""
86698673
if not zone_id:
86708674
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
8675+
# It should be noted that the actual Content-Type header that will be
8676+
# sent to the server will contain a `boundary` parameter, e.g.
8677+
# multipart/form-data; boundary=---abc--
8678+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
86718679
return await self._post(
86728680
f"/zones/{zone_id}/dns_records/import",
86738681
body=await async_maybe_transform(

src/cloudflare/resources/images/v1/v1.py

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def create(
133133
"""
134134
if not account_id:
135135
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
136+
# It should be noted that the actual Content-Type header that will be
137+
# sent to the server will contain a `boundary` parameter, e.g.
138+
# multipart/form-data; boundary=---abc--
139+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
136140
return self._post(
137141
f"/accounts/{account_id}/images/v1",
138142
body=maybe_transform(
@@ -434,6 +438,10 @@ async def create(
434438
"""
435439
if not account_id:
436440
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
441+
# It should be noted that the actual Content-Type header that will be
442+
# sent to the server will contain a `boundary` parameter, e.g.
443+
# multipart/form-data; boundary=---abc--
444+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
437445
return await self._post(
438446
f"/accounts/{account_id}/images/v1",
439447
body=await async_maybe_transform(

src/cloudflare/resources/images/v2/direct_uploads.py

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def create(
8989
"""
9090
if not account_id:
9191
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
92+
# It should be noted that the actual Content-Type header that will be
93+
# sent to the server will contain a `boundary` parameter, e.g.
94+
# multipart/form-data; boundary=---abc--
95+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
9296
return self._post(
9397
f"/accounts/{account_id}/images/v2/direct_upload",
9498
body=maybe_transform(
@@ -170,6 +174,10 @@ async def create(
170174
"""
171175
if not account_id:
172176
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
177+
# It should be noted that the actual Content-Type header that will be
178+
# sent to the server will contain a `boundary` parameter, e.g.
179+
# multipart/form-data; boundary=---abc--
180+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
173181
return await self._post(
174182
f"/accounts/{account_id}/images/v2/direct_upload",
175183
body=await async_maybe_transform(

src/cloudflare/resources/intel/indicator_feeds/snapshots.py

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def update(
7171
"""
7272
if not account_id:
7373
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
74+
# It should be noted that the actual Content-Type header that will be
75+
# sent to the server will contain a `boundary` parameter, e.g.
76+
# multipart/form-data; boundary=---abc--
77+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
7478
return self._put(
7579
f"/accounts/{account_id}/intel/indicator-feeds/{feed_id}/snapshot",
7680
body=maybe_transform({"source": source}, snapshot_update_params.SnapshotUpdateParams),
@@ -127,6 +131,10 @@ async def update(
127131
"""
128132
if not account_id:
129133
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
134+
# It should be noted that the actual Content-Type header that will be
135+
# sent to the server will contain a `boundary` parameter, e.g.
136+
# multipart/form-data; boundary=---abc--
137+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
130138
return await self._put(
131139
f"/accounts/{account_id}/intel/indicator-feeds/{feed_id}/snapshot",
132140
body=await async_maybe_transform({"source": source}, snapshot_update_params.SnapshotUpdateParams),

src/cloudflare/resources/kv/namespaces/values.py

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def update(
9797
raise ValueError(f"Expected a non-empty value for `namespace_id` but received {namespace_id!r}")
9898
if not key_name:
9999
raise ValueError(f"Expected a non-empty value for `key_name` but received {key_name!r}")
100+
# It should be noted that the actual Content-Type header that will be
101+
# sent to the server will contain a `boundary` parameter, e.g.
102+
# multipart/form-data; boundary=---abc--
103+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
100104
return self._put(
101105
f"/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}",
102106
body=maybe_transform(
@@ -280,6 +284,10 @@ async def update(
280284
raise ValueError(f"Expected a non-empty value for `namespace_id` but received {namespace_id!r}")
281285
if not key_name:
282286
raise ValueError(f"Expected a non-empty value for `key_name` but received {key_name!r}")
287+
# It should be noted that the actual Content-Type header that will be
288+
# sent to the server will contain a `boundary` parameter, e.g.
289+
# multipart/form-data; boundary=---abc--
290+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
283291
return await self._put(
284292
f"/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}",
285293
body=await async_maybe_transform(

src/cloudflare/resources/pages/projects/deployments/deployments.py

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def create(
9797
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
9898
if not project_name:
9999
raise ValueError(f"Expected a non-empty value for `project_name` but received {project_name!r}")
100+
# It should be noted that the actual Content-Type header that will be
101+
# sent to the server will contain a `boundary` parameter, e.g.
102+
# multipart/form-data; boundary=---abc--
103+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
100104
return self._post(
101105
f"/accounts/{account_id}/pages/projects/{project_name}/deployments",
102106
body=maybe_transform({"branch": branch}, deployment_create_params.DeploymentCreateParams),
@@ -408,6 +412,10 @@ async def create(
408412
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
409413
if not project_name:
410414
raise ValueError(f"Expected a non-empty value for `project_name` but received {project_name!r}")
415+
# It should be noted that the actual Content-Type header that will be
416+
# sent to the server will contain a `boundary` parameter, e.g.
417+
# multipart/form-data; boundary=---abc--
418+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
411419
return await self._post(
412420
f"/accounts/{account_id}/pages/projects/{project_name}/deployments",
413421
body=await async_maybe_transform({"branch": branch}, deployment_create_params.DeploymentCreateParams),

src/cloudflare/resources/snippets/snippets.py

+8
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def update(
101101
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
102102
if not snippet_name:
103103
raise ValueError(f"Expected a non-empty value for `snippet_name` but received {snippet_name!r}")
104+
# It should be noted that the actual Content-Type header that will be
105+
# sent to the server will contain a `boundary` parameter, e.g.
106+
# multipart/form-data; boundary=---abc--
107+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
104108
return self._put(
105109
f"/zones/{zone_id}/snippets/{snippet_name}",
106110
body=maybe_transform(
@@ -294,6 +298,10 @@ async def update(
294298
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
295299
if not snippet_name:
296300
raise ValueError(f"Expected a non-empty value for `snippet_name` but received {snippet_name!r}")
301+
# It should be noted that the actual Content-Type header that will be
302+
# sent to the server will contain a `boundary` parameter, e.g.
303+
# multipart/form-data; boundary=---abc--
304+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
297305
return await self._put(
298306
f"/zones/{zone_id}/snippets/{snippet_name}",
299307
body=await async_maybe_transform(

src/cloudflare/resources/stream/captions/language/language.py

+8
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def update(
141141
raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}")
142142
if not language:
143143
raise ValueError(f"Expected a non-empty value for `language` but received {language!r}")
144+
# It should be noted that the actual Content-Type header that will be
145+
# sent to the server will contain a `boundary` parameter, e.g.
146+
# multipart/form-data; boundary=---abc--
147+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
144148
return self._put(
145149
f"/accounts/{account_id}/stream/{identifier}/captions/{language}",
146150
body=maybe_transform({"file": file}, language_update_params.LanguageUpdateParams),
@@ -356,6 +360,10 @@ async def update(
356360
raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}")
357361
if not language:
358362
raise ValueError(f"Expected a non-empty value for `language` but received {language!r}")
363+
# It should be noted that the actual Content-Type header that will be
364+
# sent to the server will contain a `boundary` parameter, e.g.
365+
# multipart/form-data; boundary=---abc--
366+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
359367
return await self._put(
360368
f"/accounts/{account_id}/stream/{identifier}/captions/{language}",
361369
body=await async_maybe_transform({"file": file}, language_update_params.LanguageUpdateParams),

src/cloudflare/resources/stream/watermarks.py

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def create(
9696
"""
9797
if not account_id:
9898
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
99+
# It should be noted that the actual Content-Type header that will be
100+
# sent to the server will contain a `boundary` parameter, e.g.
101+
# multipart/form-data; boundary=---abc--
102+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
99103
return self._post(
100104
f"/accounts/{account_id}/stream/watermarks",
101105
body=maybe_transform(
@@ -313,6 +317,10 @@ async def create(
313317
"""
314318
if not account_id:
315319
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
320+
# It should be noted that the actual Content-Type header that will be
321+
# sent to the server will contain a `boundary` parameter, e.g.
322+
# multipart/form-data; boundary=---abc--
323+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
316324
return await self._post(
317325
f"/accounts/{account_id}/stream/watermarks",
318326
body=await async_maybe_transform(

src/cloudflare/resources/workers/scripts/content.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ def update(
111111
}
112112
)
113113
files = extract_files(cast(Mapping[str, object], body), paths=[["<any part name>", "<array>"]])
114-
if files:
115-
# It should be noted that the actual Content-Type header that will be
116-
# sent to the server will contain a `boundary` parameter, e.g.
117-
# multipart/form-data; boundary=---abc--
118-
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
114+
# It should be noted that the actual Content-Type header that will be
115+
# sent to the server will contain a `boundary` parameter, e.g.
116+
# multipart/form-data; boundary=---abc--
117+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
119118
return self._put(
120119
f"/accounts/{account_id}/workers/scripts/{script_name}/content",
121120
body=maybe_transform(body, content_update_params.ContentUpdateParams),
@@ -242,11 +241,10 @@ async def update(
242241
}
243242
)
244243
files = extract_files(cast(Mapping[str, object], body), paths=[["<any part name>", "<array>"]])
245-
if files:
246-
# It should be noted that the actual Content-Type header that will be
247-
# sent to the server will contain a `boundary` parameter, e.g.
248-
# multipart/form-data; boundary=---abc--
249-
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
244+
# It should be noted that the actual Content-Type header that will be
245+
# sent to the server will contain a `boundary` parameter, e.g.
246+
# multipart/form-data; boundary=---abc--
247+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
250248
return await self._put(
251249
f"/accounts/{account_id}/workers/scripts/{script_name}/content",
252250
body=await async_maybe_transform(body, content_update_params.ContentUpdateParams),

0 commit comments

Comments
 (0)