-
Notifications
You must be signed in to change notification settings - Fork 51
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
[doc] client code of paging operation #2269
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,259 @@ | ||||||
--- | ||||||
title: Paging Operations | ||||||
--- | ||||||
|
||||||
import { ClientTabs, ClientTabItem } from "@components/client-tabs"; | ||||||
|
||||||
This doc details what emitters will generate for paging operations. | ||||||
|
||||||
## Using next link to indicate how to get the next page | ||||||
|
||||||
Next link is an absolute url that returned by paging operation, which indicate how to get the next page. | ||||||
If the response does not return next link, it should be the last page. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Next link should be annotated in response model with `@nextLink`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
There are two ways to indicate the paging operation with `@nextLink`: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
1. Use `@pagedResult` and `@items` in `Azure.Core` lib. | ||||||
|
||||||
<ClientTabs> | ||||||
|
||||||
```typespec | ||||||
op listWithPage(): UserList; | ||||||
|
||||||
model User { | ||||||
id: string; | ||||||
name: string; | ||||||
} | ||||||
|
||||||
@pagedResult | ||||||
model UserList { | ||||||
@items | ||||||
value: User[]; | ||||||
|
||||||
@nextLink | ||||||
nextLink?: url; | ||||||
} | ||||||
``` | ||||||
|
||||||
```python | ||||||
# TODO | ||||||
``` | ||||||
|
||||||
```csharp | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```typescript | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```java | ||||||
public PagedIterable<User> listWithPage(); | ||||||
``` | ||||||
|
||||||
</ClientTabs> | ||||||
|
||||||
2. Use `@list` and `@pageItems` in core. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
<ClientTabs> | ||||||
|
||||||
```typespec | ||||||
@list | ||||||
op listWithPage(): UserList; | ||||||
|
||||||
model User { | ||||||
id: string; | ||||||
name: string; | ||||||
} | ||||||
|
||||||
model UserList { | ||||||
@pageItems | ||||||
value: User[]; | ||||||
|
||||||
@nextLink | ||||||
nextLink?: url; | ||||||
} | ||||||
``` | ||||||
|
||||||
```python | ||||||
# TODO | ||||||
``` | ||||||
|
||||||
```csharp | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```typescript | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```java | ||||||
public PagedIterable<User> listWithPage(); | ||||||
``` | ||||||
|
||||||
</ClientTabs> | ||||||
|
||||||
## Using continuation token to indicate how to get the next page | ||||||
|
||||||
Continuation token is a string that returned by paging operation, which could be used as a parameter value for the paging operation to get the next page. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
If the response does not return continuation token, it should be the last page. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Continuation token should be annotated in one of the request parameter with `@continuationToken`, as well as response model with `@continuationToken`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
1. Continuation token in query parameter and response body. | ||||||
|
||||||
<ClientTabs> | ||||||
|
||||||
```typespec | ||||||
@list | ||||||
op listWithPage(@query @continuationToken continuationToken?: string): UserList; | ||||||
|
||||||
model User { | ||||||
id: string; | ||||||
name: string; | ||||||
} | ||||||
|
||||||
model UserList { | ||||||
@pageItems | ||||||
value: User[]; | ||||||
|
||||||
@continuationToken | ||||||
continuationToken?: string; | ||||||
} | ||||||
``` | ||||||
|
||||||
```python | ||||||
# TODO | ||||||
``` | ||||||
|
||||||
```csharp | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```typescript | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```java | ||||||
NOT_SUPPORTED | ||||||
``` | ||||||
|
||||||
</ClientTabs> | ||||||
|
||||||
2. Continuation token in header parameter and response body. | ||||||
|
||||||
<ClientTabs> | ||||||
|
||||||
```typespec | ||||||
@list | ||||||
op listWithPage(@header @continuationToken continuationToken?: string): UserList; | ||||||
|
||||||
model User { | ||||||
id: string; | ||||||
name: string; | ||||||
} | ||||||
|
||||||
model UserList { | ||||||
@pageItems | ||||||
value: User[]; | ||||||
|
||||||
@continuationToken | ||||||
continuationToken?: string; | ||||||
} | ||||||
``` | ||||||
|
||||||
```python | ||||||
# TODO | ||||||
``` | ||||||
|
||||||
```csharp | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```typescript | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```java | ||||||
NOT_SUPPORTED | ||||||
``` | ||||||
|
||||||
</ClientTabs> | ||||||
|
||||||
3. Continuation token in query parameter and response header. | ||||||
|
||||||
<ClientTabs> | ||||||
|
||||||
```typespec | ||||||
@list | ||||||
op listWithPage(@query @continuationToken continuationToken?: string): { | ||||||
@header | ||||||
@continuationToken | ||||||
continuationToken?: string; | ||||||
|
||||||
@pageItems | ||||||
value: User[]; | ||||||
}; | ||||||
|
||||||
model User { | ||||||
id: string; | ||||||
name: string; | ||||||
} | ||||||
``` | ||||||
|
||||||
```python | ||||||
# TODO | ||||||
``` | ||||||
|
||||||
```csharp | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```typescript | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```java | ||||||
NOT_SUPPORTED | ||||||
``` | ||||||
|
||||||
</ClientTabs> | ||||||
|
||||||
4. Continuation token in header parameter and response header. | ||||||
|
||||||
<ClientTabs> | ||||||
|
||||||
```typespec | ||||||
@list | ||||||
op listWithPage(@query @continuationToken continuationToken?: string): { | ||||||
@header | ||||||
@continuationToken | ||||||
continuationToken?: string; | ||||||
|
||||||
@pageItems | ||||||
value: User[]; | ||||||
}; | ||||||
|
||||||
model User { | ||||||
id: string; | ||||||
name: string; | ||||||
} | ||||||
``` | ||||||
|
||||||
```python | ||||||
# TODO | ||||||
``` | ||||||
|
||||||
```csharp | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```typescript | ||||||
// TODO | ||||||
``` | ||||||
|
||||||
```java | ||||||
NOT_SUPPORTED | ||||||
``` | ||||||
|
||||||
</ClientTabs> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.