Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Next link is an absolute url that returned by paging operation, which indicate how to get the next page.
Next link is an absolute url returned by the paging operation, which indicates how to get the next page.

If the response does not return next link, it should be the last page.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If the response does not return next link, it should be the last page.
If the response does not return a next link, it indicates the last page of results.

Next link should be annotated in response model with `@nextLink`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Next link should be annotated in response model with `@nextLink`.
Next link should be annotated in the response model with `@nextLink`.


There are two ways to indicate the paging operation with `@nextLink`:
Copy link
Member

Choose a reason for hiding this comment

The 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 are two ways to indicate a paging operation with `@nextLink`:


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
// TODO
```

</ClientTabs>

2. Use `@list` and `@pageItems` in core.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Use `@list` and `@pageItems` in core.
2. Use the `@list` and `@pageItems` decorators from TypeSpec core.


<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
// TODO
```

</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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.

If the response does not return continuation token, it should be the last page.
Copy link
Member

Choose a reason for hiding this comment

The 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.
If the response does not return a continuation token, it indicates the last page of results.

Continuation token should be annotated in one of the request parameter with `@continuationToken`, as well as response model with `@continuationToken`.
Copy link
Member

Choose a reason for hiding this comment

The 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`.
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`.


1. Continuation token in query parameter and response body.

<ClientTabs>

```typespec
@list
op listWithPage(@query @continuationToken token?: string): UserList;

model User {
id: string;
name: string;
}

model UserList {
@pageItems
value: User[];

@continuationToken
nextToken?: string;
}
```

```python
# TODO
```

```csharp
// TODO
```

```typescript
// TODO
```

```java
// TODO
```

</ClientTabs>

2. Continuation token in header parameter and response body.

<ClientTabs>

```typespec
@list
op listWithPage(@header @continuationToken token?: string): UserList;

model User {
id: string;
name: string;
}

model UserList {
@pageItems
value: User[];

@continuationToken
nextToken?: string;
}
```

```python
# TODO
```

```csharp
// TODO
```

```typescript
// TODO
```

```java
// TODO
```

</ClientTabs>

3. Continuation token in query parameter and response header.

<ClientTabs>

```typespec
@list
op listWithPage(@query @continuationToken token?: string): {
@header
@continuationToken
nextToken?: string;

@pageItems
value: User[];
};

model User {
id: string;
name: string;
}
```

```python
# TODO
```

```csharp
// TODO
```

```typescript
// TODO
```

```java
// TODO
```

</ClientTabs>

4. Continuation token in header parameter and response header.

<ClientTabs>

```typespec
@list
op listWithPage(@query @continuationToken token?: string): {
@header
@continuationToken
nextToken?: string;

@pageItems
value: User[];
};

model User {
id: string;
name: string;
}
```

```python
# TODO
```

```csharp
// TODO
```

```typescript
// TODO
```

```java
// TODO
```

</ClientTabs>
Loading