Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 5, 2024
1 parent 4a0644f commit 94c8879
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1254
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-d4312bd23a02e20e5d46c142ec08fbe09bb97ce586a900e10d178982734f44ec.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-397336292b6904c10bbe601d75c2153455422a23f3c97a4d6b25087ceab822ad.yml
20 changes: 18 additions & 2 deletions src/cloudflare/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
HttpxSendArgs,
AsyncTransport,
RequestOptions,
HttpxRequestFiles,
ModelBuilderProtocol,
)
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
Expand Down Expand Up @@ -459,6 +460,7 @@ def _build_request(
headers = self._build_headers(options)
params = _merge_mappings(self.default_query, options.params)
content_type = headers.get("Content-Type")
files = options.files

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

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

# httpx determines whether or not to send a "multipart/form-data"
# request based on the truthiness of the "files" argument.
# This gets around that issue by generating a dict value that
# evaluates to true.
#
# https://github.com/encode/httpx/discussions/2399#discussioncomment-3814186
if not files:
files = cast(HttpxRequestFiles, ForceMultipartDict())

# TODO: report this error to httpx
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
headers=headers,
Expand All @@ -492,7 +503,7 @@ def _build_request(
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
json=json_data,
files=options.files,
files=files,
**kwargs,
)

Expand Down Expand Up @@ -1863,6 +1874,11 @@ def make_request_options(
return options


class ForceMultipartDict(Dict[str, None]):
def __bool__(self) -> bool:
return True


class OtherPlatform:
def __init__(self, name: str) -> None:
self.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/accounts/{account_id}/addressing/loa_documents",
body=maybe_transform({"loa_document": loa_document}, loa_document_create_params.LOADocumentCreateParams),
Expand Down Expand Up @@ -137,6 +141,10 @@ async def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/accounts/{account_id}/addressing/loa_documents",
body=await async_maybe_transform(
Expand Down
18 changes: 8 additions & 10 deletions src/cloudflare/resources/api_gateway/user_schemas/user_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ def create(
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
if files:
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/zones/{zone_id}/api_gateway/user_schemas",
body=maybe_transform(body, user_schema_create_params.UserSchemaCreateParams),
Expand Down Expand Up @@ -392,11 +391,10 @@ async def create(
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
if files:
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/zones/{zone_id}/api_gateway/user_schemas",
body=await async_maybe_transform(body, user_schema_create_params.UserSchemaCreateParams),
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/dns/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -4326,6 +4326,10 @@ def import_(
"""
if not zone_id:
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/zones/{zone_id}/dns_records/import",
body=maybe_transform(
Expand Down Expand Up @@ -8668,6 +8672,10 @@ async def import_(
"""
if not zone_id:
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/zones/{zone_id}/dns_records/import",
body=await async_maybe_transform(
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/images/v1/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/accounts/{account_id}/images/v1",
body=maybe_transform(
Expand Down Expand Up @@ -434,6 +438,10 @@ async def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/accounts/{account_id}/images/v1",
body=await async_maybe_transform(
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/images/v2/direct_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/accounts/{account_id}/images/v2/direct_upload",
body=maybe_transform(
Expand Down Expand Up @@ -170,6 +174,10 @@ async def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/accounts/{account_id}/images/v2/direct_upload",
body=await async_maybe_transform(
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/intel/indicator_feeds/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def update(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._put(
f"/accounts/{account_id}/intel/indicator-feeds/{feed_id}/snapshot",
body=maybe_transform({"source": source}, snapshot_update_params.SnapshotUpdateParams),
Expand Down Expand Up @@ -127,6 +131,10 @@ async def update(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._put(
f"/accounts/{account_id}/intel/indicator-feeds/{feed_id}/snapshot",
body=await async_maybe_transform({"source": source}, snapshot_update_params.SnapshotUpdateParams),
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/kv/namespaces/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def update(
raise ValueError(f"Expected a non-empty value for `namespace_id` but received {namespace_id!r}")
if not key_name:
raise ValueError(f"Expected a non-empty value for `key_name` but received {key_name!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._put(
f"/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}",
body=maybe_transform(
Expand Down Expand Up @@ -280,6 +284,10 @@ async def update(
raise ValueError(f"Expected a non-empty value for `namespace_id` but received {namespace_id!r}")
if not key_name:
raise ValueError(f"Expected a non-empty value for `key_name` but received {key_name!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._put(
f"/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}",
body=await async_maybe_transform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def create(
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not project_name:
raise ValueError(f"Expected a non-empty value for `project_name` but received {project_name!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/accounts/{account_id}/pages/projects/{project_name}/deployments",
body=maybe_transform({"branch": branch}, deployment_create_params.DeploymentCreateParams),
Expand Down Expand Up @@ -408,6 +412,10 @@ async def create(
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not project_name:
raise ValueError(f"Expected a non-empty value for `project_name` but received {project_name!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/accounts/{account_id}/pages/projects/{project_name}/deployments",
body=await async_maybe_transform({"branch": branch}, deployment_create_params.DeploymentCreateParams),
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/snippets/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def update(
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
if not snippet_name:
raise ValueError(f"Expected a non-empty value for `snippet_name` but received {snippet_name!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._put(
f"/zones/{zone_id}/snippets/{snippet_name}",
body=maybe_transform(
Expand Down Expand Up @@ -294,6 +298,10 @@ async def update(
raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
if not snippet_name:
raise ValueError(f"Expected a non-empty value for `snippet_name` but received {snippet_name!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._put(
f"/zones/{zone_id}/snippets/{snippet_name}",
body=await async_maybe_transform(
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/stream/captions/language/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def update(
raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}")
if not language:
raise ValueError(f"Expected a non-empty value for `language` but received {language!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._put(
f"/accounts/{account_id}/stream/{identifier}/captions/{language}",
body=maybe_transform({"file": file}, language_update_params.LanguageUpdateParams),
Expand Down Expand Up @@ -356,6 +360,10 @@ async def update(
raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}")
if not language:
raise ValueError(f"Expected a non-empty value for `language` but received {language!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._put(
f"/accounts/{account_id}/stream/{identifier}/captions/{language}",
body=await async_maybe_transform({"file": file}, language_update_params.LanguageUpdateParams),
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/stream/watermarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
f"/accounts/{account_id}/stream/watermarks",
body=maybe_transform(
Expand Down Expand Up @@ -313,6 +317,10 @@ async def create(
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
f"/accounts/{account_id}/stream/watermarks",
body=await async_maybe_transform(
Expand Down
18 changes: 8 additions & 10 deletions src/cloudflare/resources/workers/scripts/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ def update(
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["<any part name>", "<array>"]])
if files:
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._put(
f"/accounts/{account_id}/workers/scripts/{script_name}/content",
body=maybe_transform(body, content_update_params.ContentUpdateParams),
Expand Down Expand Up @@ -242,11 +241,10 @@ async def update(
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["<any part name>", "<array>"]])
if files:
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._put(
f"/accounts/{account_id}/workers/scripts/{script_name}/content",
body=await async_maybe_transform(body, content_update_params.ContentUpdateParams),
Expand Down
Loading

0 comments on commit 94c8879

Please sign in to comment.