Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Apr 1, 2024
1 parent 5d528fc commit d19970f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ response = client.post(
print(response.headers.get("x-foo"))
```

#### Undocumented params
#### Undocumented request params

If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
options.

#### Undocumented properties
#### Undocumented response properties

To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
can also get all the extra fields on the Pydantic model as a dict with
Expand Down
5 changes: 5 additions & 0 deletions src/cloudflare/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ def __init__(
self._strict_response_validation = _strict_response_validation
self._idempotency_header = None

if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
raise TypeError(
"max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `cloudflare.DEFAULT_MAX_RETRIES`"
)

def _enforce_trailing_slash(self, url: URL) -> URL:
if url.raw_path.endswith(b"/"):
return url
Expand Down
20 changes: 20 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,16 @@ class Model(BaseModel):

assert isinstance(exc.value.__cause__, ValidationError)

def test_client_max_retries_validation(self) -> None:
with pytest.raises(TypeError, match=r"max_retries cannot be None"):
Cloudflare(
base_url=base_url,
api_key=api_key,
api_email=api_email,
_strict_response_validation=True,
max_retries=cast(Any, None),
)

@pytest.mark.respx(base_url=base_url)
def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None:
class Model(BaseModel):
Expand Down Expand Up @@ -1493,6 +1503,16 @@ class Model(BaseModel):

assert isinstance(exc.value.__cause__, ValidationError)

async def test_client_max_retries_validation(self) -> None:
with pytest.raises(TypeError, match=r"max_retries cannot be None"):
AsyncCloudflare(
base_url=base_url,
api_key=api_key,
api_email=api_email,
_strict_response_validation=True,
max_retries=cast(Any, None),
)

@pytest.mark.respx(base_url=base_url)
@pytest.mark.asyncio
async def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None:
Expand Down

0 comments on commit d19970f

Please sign in to comment.