Skip to content

feat(api): benefits mutation API endpoints (create benefit, update benefit, enroll individual, unenroll individual) now properly return async response types #649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 46
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-8c83f0eae70d2a02ed3e2059fc251affdccd2f848f45445e4fed64dfd9ca5985.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-bf858f37d7ab420841ddc6329dad8c46377308b6a5c8e935908011d0f9845e22.yml
openapi_spec_hash: 2523952a32436e3c7fd3b55508c2e7ee
config_hash: ce10384813f68ba3fed61c7b601b396b
config_hash: 4a8def48077df6382ed9fe00588baecf
6 changes: 3 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ Types:

```python
from finch.types.hris.benefits import (
EnrolledIndividualBenifit,
IndividualBenefit,
IndividualEnrollManyResponse,
IndividualEnrolledIDsResponse,
IndividualUnenrollManyResponse,
)
```

Methods:

- <code title="post /employer/benefits/{benefit_id}/individuals">client.hris.benefits.individuals.<a href="./src/finch/resources/hris/benefits/individuals.py">enroll_many</a>(benefit_id, \*\*<a href="src/finch/types/hris/benefits/individual_enroll_many_params.py">params</a>) -> <a href="./src/finch/types/hris/benefits/individual_enroll_many_response.py">IndividualEnrollManyResponse</a></code>
- <code title="post /employer/benefits/{benefit_id}/individuals">client.hris.benefits.individuals.<a href="./src/finch/resources/hris/benefits/individuals.py">enroll_many</a>(benefit_id, \*\*<a href="src/finch/types/hris/benefits/individual_enroll_many_params.py">params</a>) -> <a href="./src/finch/types/hris/benefits/enrolled_individual_benifit.py">EnrolledIndividualBenifit</a></code>
- <code title="get /employer/benefits/{benefit_id}/enrolled">client.hris.benefits.individuals.<a href="./src/finch/resources/hris/benefits/individuals.py">enrolled_ids</a>(benefit_id) -> <a href="./src/finch/types/hris/benefits/individual_enrolled_ids_response.py">IndividualEnrolledIDsResponse</a></code>
- <code title="get /employer/benefits/{benefit_id}/individuals">client.hris.benefits.individuals.<a href="./src/finch/resources/hris/benefits/individuals.py">retrieve_many_benefits</a>(benefit_id, \*\*<a href="src/finch/types/hris/benefits/individual_retrieve_many_benefits_params.py">params</a>) -> <a href="./src/finch/types/hris/benefits/individual_benefit.py">SyncSinglePage[IndividualBenefit]</a></code>
- <code title="delete /employer/benefits/{benefit_id}/individuals">client.hris.benefits.individuals.<a href="./src/finch/resources/hris/benefits/individuals.py">unenroll_many</a>(benefit_id, \*\*<a href="src/finch/types/hris/benefits/individual_unenroll_many_params.py">params</a>) -> <a href="./src/finch/types/hris/benefits/individual_unenroll_many_response.py">SyncSinglePage[object]</a></code>
- <code title="delete /employer/benefits/{benefit_id}/individuals">client.hris.benefits.individuals.<a href="./src/finch/resources/hris/benefits/individuals.py">unenroll_many</a>(benefit_id, \*\*<a href="src/finch/types/hris/benefits/individual_unenroll_many_params.py">params</a>) -> <a href="./src/finch/types/hris/benefits/individual_unenroll_many_response.py">IndividualUnenrollManyResponse</a></code>

# Providers

Expand Down
31 changes: 14 additions & 17 deletions src/finch/resources/hris/benefits/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
individual_retrieve_many_benefits_params,
)
from ....types.hris.benefits.individual_benefit import IndividualBenefit
from ....types.hris.benefits.individual_enroll_many_response import IndividualEnrollManyResponse
from ....types.hris.benefits.enrolled_individual_benifit import EnrolledIndividualBenifit
from ....types.hris.benefits.individual_enrolled_ids_response import IndividualEnrolledIDsResponse
from ....types.hris.benefits.individual_unenroll_many_response import IndividualUnenrollManyResponse

__all__ = ["Individuals", "AsyncIndividuals"]

Expand Down Expand Up @@ -60,7 +61,7 @@ def enroll_many(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> IndividualEnrollManyResponse:
) -> EnrolledIndividualBenifit:
"""Enroll an individual into a deduction or contribution.

This is an overwrite
Expand All @@ -87,7 +88,7 @@ def enroll_many(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=IndividualEnrollManyResponse,
cast_to=EnrolledIndividualBenifit,
)

def enrolled_ids(
Expand Down Expand Up @@ -179,7 +180,7 @@ def unenroll_many(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> SyncSinglePage[object]:
) -> IndividualUnenrollManyResponse:
"""
Unenroll individuals from a deduction or contribution

Expand All @@ -196,17 +197,15 @@ def unenroll_many(
"""
if not benefit_id:
raise ValueError(f"Expected a non-empty value for `benefit_id` but received {benefit_id!r}")
return self._get_api_list(
return self._delete(
f"/employer/benefits/{benefit_id}/individuals",
page=SyncSinglePage[object],
body=maybe_transform(
{"individual_ids": individual_ids}, individual_unenroll_many_params.IndividualUnenrollManyParams
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
model=object,
method="delete",
cast_to=IndividualUnenrollManyResponse,
)


Expand Down Expand Up @@ -241,7 +240,7 @@ async def enroll_many(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> IndividualEnrollManyResponse:
) -> EnrolledIndividualBenifit:
"""Enroll an individual into a deduction or contribution.

This is an overwrite
Expand All @@ -268,7 +267,7 @@ async def enroll_many(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=IndividualEnrollManyResponse,
cast_to=EnrolledIndividualBenifit,
)

async def enrolled_ids(
Expand Down Expand Up @@ -349,7 +348,7 @@ def retrieve_many_benefits(
model=IndividualBenefit,
)

def unenroll_many(
async def unenroll_many(
self,
benefit_id: str,
*,
Expand All @@ -360,7 +359,7 @@ def unenroll_many(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> AsyncPaginator[object, AsyncSinglePage[object]]:
) -> IndividualUnenrollManyResponse:
"""
Unenroll individuals from a deduction or contribution

Expand All @@ -377,17 +376,15 @@ def unenroll_many(
"""
if not benefit_id:
raise ValueError(f"Expected a non-empty value for `benefit_id` but received {benefit_id!r}")
return self._get_api_list(
return await self._delete(
f"/employer/benefits/{benefit_id}/individuals",
page=AsyncSinglePage[object],
body=maybe_transform(
body=await async_maybe_transform(
{"individual_ids": individual_ids}, individual_unenroll_many_params.IndividualUnenrollManyParams
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
model=object,
method="delete",
cast_to=IndividualUnenrollManyResponse,
)


Expand Down
3 changes: 2 additions & 1 deletion src/finch/types/hris/benefits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from __future__ import annotations

from .individual_benefit import IndividualBenefit as IndividualBenefit
from .enrolled_individual_benifit import EnrolledIndividualBenifit as EnrolledIndividualBenifit
from .individual_enroll_many_params import IndividualEnrollManyParams as IndividualEnrollManyParams
from .individual_enroll_many_response import IndividualEnrollManyResponse as IndividualEnrollManyResponse
from .individual_unenroll_many_params import IndividualUnenrollManyParams as IndividualUnenrollManyParams
from .individual_enrolled_ids_response import IndividualEnrolledIDsResponse as IndividualEnrolledIDsResponse
from .individual_unenroll_many_response import IndividualUnenrollManyResponse as IndividualUnenrollManyResponse
from .individual_retrieve_many_benefits_params import (
IndividualRetrieveManyBenefitsParams as IndividualRetrieveManyBenefitsParams,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from ...._models import BaseModel

__all__ = ["IndividualEnrollManyResponse"]
__all__ = ["EnrolledIndividualBenifit"]


class IndividualEnrollManyResponse(BaseModel):
class EnrolledIndividualBenifit(BaseModel):
job_id: str
10 changes: 10 additions & 0 deletions src/finch/types/hris/benefits/individual_unenroll_many_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.


from ...._models import BaseModel

__all__ = ["IndividualUnenrollManyResponse"]


class IndividualUnenrollManyResponse(BaseModel):
job_id: str
35 changes: 18 additions & 17 deletions tests/api_resources/hris/benefits/test_individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from finch.pagination import SyncSinglePage, AsyncSinglePage
from finch.types.hris.benefits import (
IndividualBenefit,
IndividualEnrollManyResponse,
EnrolledIndividualBenifit,
IndividualEnrolledIDsResponse,
IndividualUnenrollManyResponse,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
Expand All @@ -28,7 +29,7 @@ def test_method_enroll_many(self, client: Finch) -> None:
individual = client.hris.benefits.individuals.enroll_many(
benefit_id="benefit_id",
)
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

@parametrize
def test_method_enroll_many_with_all_params(self, client: Finch) -> None:
Expand All @@ -54,7 +55,7 @@ def test_method_enroll_many_with_all_params(self, client: Finch) -> None:
}
],
)
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

@parametrize
def test_raw_response_enroll_many(self, client: Finch) -> None:
Expand All @@ -65,7 +66,7 @@ def test_raw_response_enroll_many(self, client: Finch) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
individual = response.parse()
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

@parametrize
def test_streaming_response_enroll_many(self, client: Finch) -> None:
Expand All @@ -76,7 +77,7 @@ def test_streaming_response_enroll_many(self, client: Finch) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

individual = response.parse()
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down Expand Up @@ -176,15 +177,15 @@ def test_method_unenroll_many(self, client: Finch) -> None:
individual = client.hris.benefits.individuals.unenroll_many(
benefit_id="benefit_id",
)
assert_matches_type(SyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

@parametrize
def test_method_unenroll_many_with_all_params(self, client: Finch) -> None:
individual = client.hris.benefits.individuals.unenroll_many(
benefit_id="benefit_id",
individual_ids=["string"],
)
assert_matches_type(SyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

@parametrize
def test_raw_response_unenroll_many(self, client: Finch) -> None:
Expand All @@ -195,7 +196,7 @@ def test_raw_response_unenroll_many(self, client: Finch) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
individual = response.parse()
assert_matches_type(SyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

@parametrize
def test_streaming_response_unenroll_many(self, client: Finch) -> None:
Expand All @@ -206,7 +207,7 @@ def test_streaming_response_unenroll_many(self, client: Finch) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

individual = response.parse()
assert_matches_type(SyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

assert cast(Any, response.is_closed) is True

Expand All @@ -226,7 +227,7 @@ async def test_method_enroll_many(self, async_client: AsyncFinch) -> None:
individual = await async_client.hris.benefits.individuals.enroll_many(
benefit_id="benefit_id",
)
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

@parametrize
async def test_method_enroll_many_with_all_params(self, async_client: AsyncFinch) -> None:
Expand All @@ -252,7 +253,7 @@ async def test_method_enroll_many_with_all_params(self, async_client: AsyncFinch
}
],
)
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

@parametrize
async def test_raw_response_enroll_many(self, async_client: AsyncFinch) -> None:
Expand All @@ -263,7 +264,7 @@ async def test_raw_response_enroll_many(self, async_client: AsyncFinch) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
individual = response.parse()
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

@parametrize
async def test_streaming_response_enroll_many(self, async_client: AsyncFinch) -> None:
Expand All @@ -274,7 +275,7 @@ async def test_streaming_response_enroll_many(self, async_client: AsyncFinch) ->
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

individual = await response.parse()
assert_matches_type(IndividualEnrollManyResponse, individual, path=["response"])
assert_matches_type(EnrolledIndividualBenifit, individual, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down Expand Up @@ -374,15 +375,15 @@ async def test_method_unenroll_many(self, async_client: AsyncFinch) -> None:
individual = await async_client.hris.benefits.individuals.unenroll_many(
benefit_id="benefit_id",
)
assert_matches_type(AsyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

@parametrize
async def test_method_unenroll_many_with_all_params(self, async_client: AsyncFinch) -> None:
individual = await async_client.hris.benefits.individuals.unenroll_many(
benefit_id="benefit_id",
individual_ids=["string"],
)
assert_matches_type(AsyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

@parametrize
async def test_raw_response_unenroll_many(self, async_client: AsyncFinch) -> None:
Expand All @@ -393,7 +394,7 @@ async def test_raw_response_unenroll_many(self, async_client: AsyncFinch) -> Non
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
individual = response.parse()
assert_matches_type(AsyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

@parametrize
async def test_streaming_response_unenroll_many(self, async_client: AsyncFinch) -> None:
Expand All @@ -404,7 +405,7 @@ async def test_streaming_response_unenroll_many(self, async_client: AsyncFinch)
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

individual = await response.parse()
assert_matches_type(AsyncSinglePage[object], individual, path=["response"])
assert_matches_type(IndividualUnenrollManyResponse, individual, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down