Skip to content

Commit f51136d

Browse files
feat: apps: add offset pagination + headers
1 parent 3528a34 commit f51136d

File tree

6 files changed

+55
-28
lines changed

6 files changed

+55
-28
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 65
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-e914e2d08b888c77051acb09176d5e88052f130e0d22e85d946a675d2c3d39ab.yml
3-
openapi_spec_hash: 611d0ed1b4519331470b5d14e5f6784a
4-
config_hash: 3ded7a0ed77b1bfd68eabc6763521fe8
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-015c11efc34c81d4d82a937c017f5eb789ea3ca21a05b70e2ed31c069b839293.yml
3+
openapi_spec_hash: 3dcab2044da305f376cecf4eca38caee
4+
config_hash: 0fbdda3a736cc2748ca33371871e61b3

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from kernel.types import AppListResponse
3535

3636
Methods:
3737

38-
- <code title="get /apps">client.apps.<a href="./src/kernel/resources/apps.py">list</a>(\*\*<a href="src/kernel/types/app_list_params.py">params</a>) -> <a href="./src/kernel/types/app_list_response.py">AppListResponse</a></code>
38+
- <code title="get /apps">client.apps.<a href="./src/kernel/resources/apps.py">list</a>(\*\*<a href="src/kernel/types/app_list_params.py">params</a>) -> <a href="./src/kernel/types/app_list_response.py">SyncOffsetPagination[AppListResponse]</a></code>
3939

4040
# Invocations
4141

src/kernel/resources/apps.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ..types import app_list_params
88
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
9-
from .._utils import maybe_transform, async_maybe_transform
9+
from .._utils import maybe_transform
1010
from .._compat import cached_property
1111
from .._resource import SyncAPIResource, AsyncAPIResource
1212
from .._response import (
@@ -15,7 +15,8 @@
1515
async_to_raw_response_wrapper,
1616
async_to_streamed_response_wrapper,
1717
)
18-
from .._base_client import make_request_options
18+
from ..pagination import SyncOffsetPagination, AsyncOffsetPagination
19+
from .._base_client import AsyncPaginator, make_request_options
1920
from ..types.app_list_response import AppListResponse
2021

2122
__all__ = ["AppsResource", "AsyncAppsResource"]
@@ -45,21 +46,27 @@ def list(
4546
self,
4647
*,
4748
app_name: str | Omit = omit,
49+
limit: int | Omit = omit,
50+
offset: int | Omit = omit,
4851
version: str | Omit = omit,
4952
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5053
# The extra values given here take precedence over values defined on the client or passed to this method.
5154
extra_headers: Headers | None = None,
5255
extra_query: Query | None = None,
5356
extra_body: Body | None = None,
5457
timeout: float | httpx.Timeout | None | NotGiven = not_given,
55-
) -> AppListResponse:
58+
) -> SyncOffsetPagination[AppListResponse]:
5659
"""List applications.
5760
5861
Optionally filter by app name and/or version label.
5962
6063
Args:
6164
app_name: Filter results by application name.
6265
66+
limit: Limit the number of app to return.
67+
68+
offset: Offset the number of app to return.
69+
6370
version: Filter results by version label.
6471
6572
extra_headers: Send extra headers
@@ -70,8 +77,9 @@ def list(
7077
7178
timeout: Override the client-level default timeout for this request, in seconds
7279
"""
73-
return self._get(
80+
return self._get_api_list(
7481
"/apps",
82+
page=SyncOffsetPagination[AppListResponse],
7583
options=make_request_options(
7684
extra_headers=extra_headers,
7785
extra_query=extra_query,
@@ -80,12 +88,14 @@ def list(
8088
query=maybe_transform(
8189
{
8290
"app_name": app_name,
91+
"limit": limit,
92+
"offset": offset,
8393
"version": version,
8494
},
8595
app_list_params.AppListParams,
8696
),
8797
),
88-
cast_to=AppListResponse,
98+
model=AppListResponse,
8999
)
90100

91101

@@ -109,25 +119,31 @@ def with_streaming_response(self) -> AsyncAppsResourceWithStreamingResponse:
109119
"""
110120
return AsyncAppsResourceWithStreamingResponse(self)
111121

112-
async def list(
122+
def list(
113123
self,
114124
*,
115125
app_name: str | Omit = omit,
126+
limit: int | Omit = omit,
127+
offset: int | Omit = omit,
116128
version: str | Omit = omit,
117129
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
118130
# The extra values given here take precedence over values defined on the client or passed to this method.
119131
extra_headers: Headers | None = None,
120132
extra_query: Query | None = None,
121133
extra_body: Body | None = None,
122134
timeout: float | httpx.Timeout | None | NotGiven = not_given,
123-
) -> AppListResponse:
135+
) -> AsyncPaginator[AppListResponse, AsyncOffsetPagination[AppListResponse]]:
124136
"""List applications.
125137
126138
Optionally filter by app name and/or version label.
127139
128140
Args:
129141
app_name: Filter results by application name.
130142
143+
limit: Limit the number of app to return.
144+
145+
offset: Offset the number of app to return.
146+
131147
version: Filter results by version label.
132148
133149
extra_headers: Send extra headers
@@ -138,22 +154,25 @@ async def list(
138154
139155
timeout: Override the client-level default timeout for this request, in seconds
140156
"""
141-
return await self._get(
157+
return self._get_api_list(
142158
"/apps",
159+
page=AsyncOffsetPagination[AppListResponse],
143160
options=make_request_options(
144161
extra_headers=extra_headers,
145162
extra_query=extra_query,
146163
extra_body=extra_body,
147164
timeout=timeout,
148-
query=await async_maybe_transform(
165+
query=maybe_transform(
149166
{
150167
"app_name": app_name,
168+
"limit": limit,
169+
"offset": offset,
151170
"version": version,
152171
},
153172
app_list_params.AppListParams,
154173
),
155174
),
156-
cast_to=AppListResponse,
175+
model=AppListResponse,
157176
)
158177

159178

src/kernel/types/app_list_params.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ class AppListParams(TypedDict, total=False):
1111
app_name: str
1212
"""Filter results by application name."""
1313

14+
limit: int
15+
"""Limit the number of app to return."""
16+
17+
offset: int
18+
"""Offset the number of app to return."""
19+
1420
version: str
1521
"""Filter results by version label."""

src/kernel/types/app_list_response.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
from typing import Dict, List
4-
from typing_extensions import Literal, TypeAlias
4+
from typing_extensions import Literal
55

66
from .._models import BaseModel
77
from .shared.app_action import AppAction
88

9-
__all__ = ["AppListResponse", "AppListResponseItem"]
9+
__all__ = ["AppListResponse"]
1010

1111

12-
class AppListResponseItem(BaseModel):
12+
class AppListResponse(BaseModel):
1313
id: str
1414
"""Unique identifier for the app version"""
1515

@@ -30,6 +30,3 @@ class AppListResponseItem(BaseModel):
3030

3131
version: str
3232
"""Version label for the application"""
33-
34-
35-
AppListResponse: TypeAlias = List[AppListResponseItem]

tests/api_resources/test_apps.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from kernel import Kernel, AsyncKernel
1111
from tests.utils import assert_matches_type
1212
from kernel.types import AppListResponse
13+
from kernel.pagination import SyncOffsetPagination, AsyncOffsetPagination
1314

1415
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
1516

@@ -21,16 +22,18 @@ class TestApps:
2122
@parametrize
2223
def test_method_list(self, client: Kernel) -> None:
2324
app = client.apps.list()
24-
assert_matches_type(AppListResponse, app, path=["response"])
25+
assert_matches_type(SyncOffsetPagination[AppListResponse], app, path=["response"])
2526

2627
@pytest.mark.skip(reason="Prism tests are disabled")
2728
@parametrize
2829
def test_method_list_with_all_params(self, client: Kernel) -> None:
2930
app = client.apps.list(
3031
app_name="app_name",
32+
limit=1,
33+
offset=0,
3134
version="version",
3235
)
33-
assert_matches_type(AppListResponse, app, path=["response"])
36+
assert_matches_type(SyncOffsetPagination[AppListResponse], app, path=["response"])
3437

3538
@pytest.mark.skip(reason="Prism tests are disabled")
3639
@parametrize
@@ -40,7 +43,7 @@ def test_raw_response_list(self, client: Kernel) -> None:
4043
assert response.is_closed is True
4144
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
4245
app = response.parse()
43-
assert_matches_type(AppListResponse, app, path=["response"])
46+
assert_matches_type(SyncOffsetPagination[AppListResponse], app, path=["response"])
4447

4548
@pytest.mark.skip(reason="Prism tests are disabled")
4649
@parametrize
@@ -50,7 +53,7 @@ def test_streaming_response_list(self, client: Kernel) -> None:
5053
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
5154

5255
app = response.parse()
53-
assert_matches_type(AppListResponse, app, path=["response"])
56+
assert_matches_type(SyncOffsetPagination[AppListResponse], app, path=["response"])
5457

5558
assert cast(Any, response.is_closed) is True
5659

@@ -64,16 +67,18 @@ class TestAsyncApps:
6467
@parametrize
6568
async def test_method_list(self, async_client: AsyncKernel) -> None:
6669
app = await async_client.apps.list()
67-
assert_matches_type(AppListResponse, app, path=["response"])
70+
assert_matches_type(AsyncOffsetPagination[AppListResponse], app, path=["response"])
6871

6972
@pytest.mark.skip(reason="Prism tests are disabled")
7073
@parametrize
7174
async def test_method_list_with_all_params(self, async_client: AsyncKernel) -> None:
7275
app = await async_client.apps.list(
7376
app_name="app_name",
77+
limit=1,
78+
offset=0,
7479
version="version",
7580
)
76-
assert_matches_type(AppListResponse, app, path=["response"])
81+
assert_matches_type(AsyncOffsetPagination[AppListResponse], app, path=["response"])
7782

7883
@pytest.mark.skip(reason="Prism tests are disabled")
7984
@parametrize
@@ -83,7 +88,7 @@ async def test_raw_response_list(self, async_client: AsyncKernel) -> None:
8388
assert response.is_closed is True
8489
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
8590
app = await response.parse()
86-
assert_matches_type(AppListResponse, app, path=["response"])
91+
assert_matches_type(AsyncOffsetPagination[AppListResponse], app, path=["response"])
8792

8893
@pytest.mark.skip(reason="Prism tests are disabled")
8994
@parametrize
@@ -93,6 +98,6 @@ async def test_streaming_response_list(self, async_client: AsyncKernel) -> None:
9398
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
9499

95100
app = await response.parse()
96-
assert_matches_type(AppListResponse, app, path=["response"])
101+
assert_matches_type(AsyncOffsetPagination[AppListResponse], app, path=["response"])
97102

98103
assert cast(Any, response.is_closed) is True

0 commit comments

Comments
 (0)