Skip to content

Commit 24122e9

Browse files
tadeleshweidongxu-microsoftmarkcowlmsyyc
authored
[doc] client code of paging operation (#2269)
resolve: #2138 --------- Co-authored-by: Weidong Xu <[email protected]> Co-authored-by: Mark Cowlishaw <[email protected]> Co-authored-by: Yuchao Yan <[email protected]>
1 parent d35ab35 commit 24122e9

7 files changed

+295
-6
lines changed

.chronus/changes/add_page_items_segments-2025-2-4-15-27-53.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- "@azure-tools/typespec-client-generator-core"
55
---
66

7-
Add `pageItemsSegments` for `SdkPagingServiceMetadata` to indicate how to get page items from response.
7+
Add `pageItemsSegments` for `SdkPagingServiceMetadata` to indicate how to get page items from response.

.chronus/changes/decorator-override-2025-2-14-15-58-44.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- "@azure-tools/typespec-client-generator-core"
55
---
66

7-
Specific scope decorator should always override all-scopes decorator
7+
Specific scope decorator should always override all-scopes decorator.

.chronus/changes/tcgc-addAccessForModelProperty-2025-2-12-16-35-32.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- "@azure-tools/typespec-client-generator-core"
55
---
66

7-
Extend `@access` to also apply to `ModelProperty`s
7+
Extend `@access` to also apply to `ModelProperty`s.

.chronus/changes/tcgc-addNamespaceFlag-2025-2-6-16-20-54.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- "@azure-tools/typespec-client-generator-core"
55
---
66

7-
Add `namespace` flag to tcgc
7+
Add `namespace` flag to tcgc.

.chronus/changes/tcgc-migrateToMutator-2025-2-4-12-45-51.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- "@azure-tools/typespec-client-generator-core"
55
---
66

7-
Move from projections to mutators
7+
Move from projections to mutators.

.chronus/changes/typespec_azure_rulsets-2024-6-19-19-0-31.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- "@azure-tools/typespec-client-generator-core"
55
---
66

7-
add linter rulesets to TCGC, for both generic and language-specific linter rules
7+
Add linter rulesets to TCGC, for both generic and language-specific linter rules.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
---
2+
title: Paging Operations
3+
---
4+
5+
import { ClientTabs, ClientTabItem } from "@components/client-tabs";
6+
7+
This doc details what emitters will generate for paging operations.
8+
9+
## Using next link to indicate how to get the next page
10+
11+
Next link is an absolute url returned by the paging operation, which indicates how to get the next page.
12+
If the response does not return a next link, it indicates the last page of results.
13+
Next link should be annotated in the response model with `@nextLink`.
14+
15+
There are two ways to indicate a paging operation with `@nextLink`:
16+
17+
1. Use `@pagedResult` and `@items` in `Azure.Core` lib.
18+
19+
<ClientTabs>
20+
21+
```typespec
22+
op listWithPage(): UserList;
23+
24+
model User {
25+
id: string;
26+
name: string;
27+
}
28+
29+
@pagedResult
30+
model UserList {
31+
@items
32+
value: User[];
33+
34+
@nextLink
35+
nextLink?: url;
36+
}
37+
```
38+
39+
```python
40+
class User(_model_base.Model):
41+
id: str = rest_field()
42+
name: str = rest_field()
43+
44+
def list_with_page(self, **kwargs: Any) -> Iterable["_models.User"]:
45+
...
46+
```
47+
48+
```csharp
49+
// TODO
50+
```
51+
52+
```typescript
53+
// TODO
54+
```
55+
56+
```java
57+
public PagedIterable<User> listWithPage();
58+
```
59+
60+
</ClientTabs>
61+
62+
2. Use the `@list` and `@pageItems` decorators from TypeSpec core.
63+
64+
<ClientTabs>
65+
66+
```typespec
67+
@list
68+
op listWithPage(): UserList;
69+
70+
model User {
71+
id: string;
72+
name: string;
73+
}
74+
75+
model UserList {
76+
@pageItems
77+
value: User[];
78+
79+
@nextLink
80+
nextLink?: url;
81+
}
82+
```
83+
84+
```python
85+
class User(_model_base.Model):
86+
id: str = rest_field()
87+
name: str = rest_field()
88+
89+
def list_with_page(self, **kwargs: Any) -> Iterable["_models.User"]:
90+
...
91+
```
92+
93+
```csharp
94+
// TODO
95+
```
96+
97+
```typescript
98+
// TODO
99+
```
100+
101+
```java
102+
public PagedIterable<User> listWithPage();
103+
```
104+
105+
</ClientTabs>
106+
107+
## Using continuation token to indicate how to get the next page
108+
109+
A continuation token is a string returned by a paging operation, which is used as a parameter value for the paging operation to get the next page.
110+
If the response does not return a continuation token, it indicates the last page of results.
111+
The request parameter that corresponds to the continuation token value in the paging operation should be decorated with `@continuationToken`. Similarly, the response property that contains the continuation token value should also be decorated with `@continuationToken`.
112+
113+
1. Continuation token in query parameter and response body.
114+
115+
<ClientTabs>
116+
117+
```typespec
118+
@list
119+
op listWithPage(@query @continuationToken continuationToken?: string): UserList;
120+
121+
model User {
122+
id: string;
123+
name: string;
124+
}
125+
126+
model UserList {
127+
@pageItems
128+
value: User[];
129+
130+
@continuationToken
131+
continuationToken?: string;
132+
}
133+
```
134+
135+
```python
136+
class User(_model_base.Model):
137+
id: str = rest_field()
138+
name: str = rest_field()
139+
140+
def list_with_page(self, **kwargs: Any) -> Iterable["_models.User"]:
141+
...
142+
```
143+
144+
```csharp
145+
// TODO
146+
```
147+
148+
```typescript
149+
// TODO
150+
```
151+
152+
```java
153+
NOT_SUPPORTED
154+
```
155+
156+
</ClientTabs>
157+
158+
2. Continuation token in header parameter and response body.
159+
160+
<ClientTabs>
161+
162+
```typespec
163+
@list
164+
op listWithPage(@header @continuationToken continuationToken?: string): UserList;
165+
166+
model User {
167+
id: string;
168+
name: string;
169+
}
170+
171+
model UserList {
172+
@pageItems
173+
value: User[];
174+
175+
@continuationToken
176+
continuationToken?: string;
177+
}
178+
```
179+
180+
```python
181+
class User(_model_base.Model):
182+
id: str = rest_field()
183+
name: str = rest_field()
184+
185+
def list_with_page(self, **kwargs: Any) -> Iterable["_models.User"]:
186+
...
187+
```
188+
189+
```csharp
190+
// TODO
191+
```
192+
193+
```typescript
194+
// TODO
195+
```
196+
197+
```java
198+
NOT_SUPPORTED
199+
```
200+
201+
</ClientTabs>
202+
203+
3. Continuation token in query parameter and response header.
204+
205+
<ClientTabs>
206+
207+
```typespec
208+
@list
209+
op listWithPage(@query @continuationToken continuationToken?: string): {
210+
@header
211+
@continuationToken
212+
continuationToken?: string;
213+
214+
@pageItems
215+
value: User[];
216+
};
217+
218+
model User {
219+
id: string;
220+
name: string;
221+
}
222+
```
223+
224+
```python
225+
class User(_model_base.Model):
226+
id: str = rest_field()
227+
name: str = rest_field()
228+
229+
def list_with_page(self, **kwargs: Any) -> Iterable["_models.User"]:
230+
...
231+
```
232+
233+
```csharp
234+
// TODO
235+
```
236+
237+
```typescript
238+
// TODO
239+
```
240+
241+
```java
242+
NOT_SUPPORTED
243+
```
244+
245+
</ClientTabs>
246+
247+
4. Continuation token in header parameter and response header.
248+
249+
<ClientTabs>
250+
251+
```typespec
252+
@list
253+
op listWithPage(@query @continuationToken continuationToken?: string): {
254+
@header
255+
@continuationToken
256+
continuationToken?: string;
257+
258+
@pageItems
259+
value: User[];
260+
};
261+
262+
model User {
263+
id: string;
264+
name: string;
265+
}
266+
```
267+
268+
```python
269+
class User(_model_base.Model):
270+
id: str = rest_field()
271+
name: str = rest_field()
272+
273+
def list_with_page(self, **kwargs: Any) -> Iterable["_models.User"]:
274+
...
275+
```
276+
277+
```csharp
278+
// TODO
279+
```
280+
281+
```typescript
282+
// TODO
283+
```
284+
285+
```java
286+
NOT_SUPPORTED
287+
```
288+
289+
</ClientTabs>

0 commit comments

Comments
 (0)