Skip to content

Commit 29b8a08

Browse files
feat(client): allow passing NotGiven for body (#600)
fix(client): mark some request bodies as optional
1 parent 88e08d2 commit 29b8a08

File tree

7 files changed

+231
-31
lines changed

7 files changed

+231
-31
lines changed

src/finch/_base_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def _build_request(
519519
# so that passing a `TypedDict` doesn't cause an error.
520520
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
521521
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
522-
json=json_data,
522+
json=json_data if is_given(json_data) else None,
523523
files=files,
524524
**kwargs,
525525
)

src/finch/resources/hris/benefits/individuals.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def enroll_many(
5151
self,
5252
benefit_id: str,
5353
*,
54-
individuals: Iterable[individual_enroll_many_params.Individual],
54+
individuals: Iterable[individual_enroll_many_params.Individual] | NotGiven = NOT_GIVEN,
5555
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5656
# The extra values given here take precedence over values defined on the client or passed to this method.
5757
extra_headers: Headers | None = None,
@@ -234,7 +234,7 @@ def enroll_many(
234234
self,
235235
benefit_id: str,
236236
*,
237-
individuals: Iterable[individual_enroll_many_params.Individual],
237+
individuals: Iterable[individual_enroll_many_params.Individual] | NotGiven = NOT_GIVEN,
238238
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
239239
# The extra values given here take precedence over values defined on the client or passed to this method.
240240
extra_headers: Headers | None = None,

src/finch/resources/sandbox/directory.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def with_streaming_response(self) -> DirectoryWithStreamingResponse:
4545
def create(
4646
self,
4747
*,
48-
body: Iterable[directory_create_params.Body],
48+
body: Iterable[directory_create_params.Body] | NotGiven = NOT_GIVEN,
4949
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5050
# The extra values given here take precedence over values defined on the client or passed to this method.
5151
extra_headers: Headers | None = None,
@@ -101,7 +101,7 @@ def with_streaming_response(self) -> AsyncDirectoryWithStreamingResponse:
101101
async def create(
102102
self,
103103
*,
104-
body: Iterable[directory_create_params.Body],
104+
body: Iterable[directory_create_params.Body] | NotGiven = NOT_GIVEN,
105105
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
106106
# The extra values given here take precedence over values defined on the client or passed to this method.
107107
extra_headers: Headers | None = None,

src/finch/types/hris/benefits/individual_enroll_many_params.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from typing import Iterable, Optional
6-
from typing_extensions import Literal, Required, TypedDict
6+
from typing_extensions import Literal, TypedDict
77

88
__all__ = [
99
"IndividualEnrollManyParams",
@@ -15,7 +15,7 @@
1515

1616

1717
class IndividualEnrollManyParams(TypedDict, total=False):
18-
individuals: Required[Iterable[Individual]]
18+
individuals: Iterable[Individual]
1919
"""Array of the individual_id to enroll and a configuration object."""
2020

2121

src/finch/types/sandbox/directory_create_params.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from typing import Iterable, Optional
6-
from typing_extensions import Literal, Required, TypedDict
6+
from typing_extensions import Literal, TypedDict
77

88
from ..income_param import IncomeParam
99
from ..location_param import LocationParam
@@ -21,7 +21,7 @@
2121

2222

2323
class DirectoryCreateParams(TypedDict, total=False):
24-
body: Required[Iterable[Body]]
24+
body: Iterable[Body]
2525
"""Array of individuals to create.
2626
2727
Takes all combined fields from `/individual` and `/employment` endpoints. All

tests/api_resources/hris/benefits/test_individuals.py

+50-8
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,38 @@ class TestIndividuals:
2727
def test_method_enroll_many(self, client: Finch) -> None:
2828
individual = client.hris.benefits.individuals.enroll_many(
2929
benefit_id="benefit_id",
30-
individuals=[{}],
30+
)
31+
assert_matches_type(SyncSinglePage[EnrolledIndividual], individual, path=["response"])
32+
33+
@parametrize
34+
def test_method_enroll_many_with_all_params(self, client: Finch) -> None:
35+
individual = client.hris.benefits.individuals.enroll_many(
36+
benefit_id="benefit_id",
37+
individuals=[
38+
{
39+
"configuration": {
40+
"annual_contribution_limit": "individual",
41+
"annual_maximum": 500000,
42+
"catch_up": False,
43+
"company_contribution": {
44+
"amount": 400,
45+
"type": "fixed",
46+
},
47+
"employee_deduction": {
48+
"amount": 1000,
49+
"type": "fixed",
50+
},
51+
},
52+
"individual_id": "d02a6346-1f08-4312-a064-49ff3cafaa7a",
53+
}
54+
],
3155
)
3256
assert_matches_type(SyncSinglePage[EnrolledIndividual], individual, path=["response"])
3357

3458
@parametrize
3559
def test_raw_response_enroll_many(self, client: Finch) -> None:
3660
response = client.hris.benefits.individuals.with_raw_response.enroll_many(
3761
benefit_id="benefit_id",
38-
individuals=[{}],
3962
)
4063

4164
assert response.is_closed is True
@@ -47,7 +70,6 @@ def test_raw_response_enroll_many(self, client: Finch) -> None:
4770
def test_streaming_response_enroll_many(self, client: Finch) -> None:
4871
with client.hris.benefits.individuals.with_streaming_response.enroll_many(
4972
benefit_id="benefit_id",
50-
individuals=[{}],
5173
) as response:
5274
assert not response.is_closed
5375
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -62,7 +84,6 @@ def test_path_params_enroll_many(self, client: Finch) -> None:
6284
with pytest.raises(ValueError, match=r"Expected a non-empty value for `benefit_id` but received ''"):
6385
client.hris.benefits.individuals.with_raw_response.enroll_many(
6486
benefit_id="",
65-
individuals=[{}],
6687
)
6788

6889
@parametrize
@@ -203,15 +224,38 @@ class TestAsyncIndividuals:
203224
async def test_method_enroll_many(self, async_client: AsyncFinch) -> None:
204225
individual = await async_client.hris.benefits.individuals.enroll_many(
205226
benefit_id="benefit_id",
206-
individuals=[{}],
227+
)
228+
assert_matches_type(AsyncSinglePage[EnrolledIndividual], individual, path=["response"])
229+
230+
@parametrize
231+
async def test_method_enroll_many_with_all_params(self, async_client: AsyncFinch) -> None:
232+
individual = await async_client.hris.benefits.individuals.enroll_many(
233+
benefit_id="benefit_id",
234+
individuals=[
235+
{
236+
"configuration": {
237+
"annual_contribution_limit": "individual",
238+
"annual_maximum": 500000,
239+
"catch_up": False,
240+
"company_contribution": {
241+
"amount": 400,
242+
"type": "fixed",
243+
},
244+
"employee_deduction": {
245+
"amount": 1000,
246+
"type": "fixed",
247+
},
248+
},
249+
"individual_id": "d02a6346-1f08-4312-a064-49ff3cafaa7a",
250+
}
251+
],
207252
)
208253
assert_matches_type(AsyncSinglePage[EnrolledIndividual], individual, path=["response"])
209254

210255
@parametrize
211256
async def test_raw_response_enroll_many(self, async_client: AsyncFinch) -> None:
212257
response = await async_client.hris.benefits.individuals.with_raw_response.enroll_many(
213258
benefit_id="benefit_id",
214-
individuals=[{}],
215259
)
216260

217261
assert response.is_closed is True
@@ -223,7 +267,6 @@ async def test_raw_response_enroll_many(self, async_client: AsyncFinch) -> None:
223267
async def test_streaming_response_enroll_many(self, async_client: AsyncFinch) -> None:
224268
async with async_client.hris.benefits.individuals.with_streaming_response.enroll_many(
225269
benefit_id="benefit_id",
226-
individuals=[{}],
227270
) as response:
228271
assert not response.is_closed
229272
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -238,7 +281,6 @@ async def test_path_params_enroll_many(self, async_client: AsyncFinch) -> None:
238281
with pytest.raises(ValueError, match=r"Expected a non-empty value for `benefit_id` but received ''"):
239282
await async_client.hris.benefits.individuals.with_raw_response.enroll_many(
240283
benefit_id="",
241-
individuals=[{}],
242284
)
243285

244286
@parametrize

0 commit comments

Comments
 (0)