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

Add paging support #4470

Merged
merged 30 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
acf5b3e
Base decorator signatures
timotheeguerin Sep 12, 2024
4b8c52b
Merge branch 'main' of https://github.com/Microsoft/typespec into paging
timotheeguerin Sep 17, 2024
72664ef
add more decorator signatures
timotheeguerin Sep 17, 2024
3dedc2b
Merge branch 'main' of https://github.com/Microsoft/typespec into paging
timotheeguerin Sep 18, 2024
676c180
Add basic validation
timotheeguerin Sep 18, 2024
e0d4c14
Progress
timotheeguerin Sep 18, 2024
97371e5
Fix and add more tests
timotheeguerin Sep 19, 2024
0bfc287
fix
timotheeguerin Sep 19, 2024
689a6d8
Add export
timotheeguerin Sep 19, 2024
3bccfea
Create paging-2024-8-19-17-3-58.md
timotheeguerin Sep 19, 2024
063ef70
Create paging-2024-8-19-17-3-59.md
timotheeguerin Sep 19, 2024
a2f220b
ADd extra validation
timotheeguerin Sep 19, 2024
efba555
Merge branch 'main' into paging
timotheeguerin Sep 19, 2024
1a598bd
Regen docs
timotheeguerin Sep 19, 2024
c5c2d7b
Fix typo
timotheeguerin Sep 19, 2024
f2512c6
Add docs
timotheeguerin Sep 19, 2024
53c6ab1
Missing file
timotheeguerin Sep 19, 2024
b3e5214
Missing file
timotheeguerin Sep 19, 2024
6d77c0d
Update docs/standard-library/pagination.md
timotheeguerin Oct 11, 2024
716a2d3
Update packages/compiler/lib/std/decorators.tsp
timotheeguerin Oct 31, 2024
970c731
Update packages/compiler/lib/std/decorators.tsp
timotheeguerin Oct 31, 2024
87c0808
Update packages/compiler/lib/std/decorators.tsp
timotheeguerin Oct 31, 2024
cb0bb7e
Update packages/compiler/lib/std/decorators.tsp
timotheeguerin Oct 31, 2024
7ae0226
Merge branch 'main' of https://github.com/Microsoft/typespec into paging
timotheeguerin Oct 31, 2024
6a28fb4
merge
timotheeguerin Oct 31, 2024
b563dda
Merge branch 'main' into paging
timotheeguerin Oct 31, 2024
d7f909e
Merge branch 'main' of https://github.com/Microsoft/typespec into paging
timotheeguerin Nov 4, 2024
e6a44e7
regen
timotheeguerin Nov 5, 2024
3c9ad0c
Merge branch 'main' of https://github.com/Microsoft/typespec into paging
timotheeguerin Nov 5, 2024
8a438cc
fix
timotheeguerin Nov 5, 2024
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
8 changes: 8 additions & 0 deletions .chronus/changes/paging-2024-8-19-17-3-58.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: feature
packages:
- "@typespec/compiler"
---

Add support for paginated operations
8 changes: 8 additions & 0 deletions .chronus/changes/paging-2024-8-19-17-3-59.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: feature
packages:
- "@typespec/http"
---

Add new `LinkHeader` pagination type
20 changes: 20 additions & 0 deletions docs/libraries/http/reference/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ model TypeSpec.Http.ImplicitFlow
| refreshUrl? | `string` | the refresh URL |
| scopes? | `string[]` | list of scopes for the credential |

### `Link` {#TypeSpec.Http.Link}

```typespec
model TypeSpec.Http.Link
```

#### Properties

| Name | Type | Description |
| ----------- | ----------------- | ----------- |
| target | `url` | |
| rel | `string` | |
| attributes? | `Record<unknown>` | |

### `LocationHeader` {#TypeSpec.Http.LocationHeader}

The Location header contains the URL where the status of the long running operation can be checked.
Expand Down Expand Up @@ -594,3 +608,9 @@ enum TypeSpec.Http.OAuth2FlowType
| implicit | | implicit flow |
| password | | password flow |
| clientCredentials | | client credential flow |

### `LinkHeader` {#TypeSpec.Http.LinkHeader}

```typespec
scalar TypeSpec.Http.LinkHeader
```
1 change: 1 addition & 0 deletions docs/libraries/http/reference/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ npm install --save-peer @typespec/http
- [`HttpPart`](./data-types.md#TypeSpec.Http.HttpPart)
- [`HttpPartOptions`](./data-types.md#TypeSpec.Http.HttpPartOptions)
- [`ImplicitFlow`](./data-types.md#TypeSpec.Http.ImplicitFlow)
- [`Link`](./data-types.md#TypeSpec.Http.Link)
- [`LocationHeader`](./data-types.md#TypeSpec.Http.LocationHeader)
- [`MovedResponse`](./data-types.md#TypeSpec.Http.MovedResponse)
- [`NoAuth`](./data-types.md#TypeSpec.Http.NoAuth)
Expand Down
250 changes: 245 additions & 5 deletions docs/standard-library/built-in-decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ toc_max_heading_level: 3
---
# Built-in Decorators
## TypeSpec
### `@continuationToken` {#@continuationToken}

Pagination property defining the token to get to the next page.
It MUST be specified both on the request parameter and the response.
```typespec
@continuationToken
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
@continuationToken continuationToken: string;
}
@list op listPets(@continuationToken continuationToken: string): Page<Pet>;
```


### `@deprecated` {#@deprecated}
:::warning
**Deprecated**: @deprecated decorator is deprecated. Use the `#deprecated` directive instead.
Expand Down Expand Up @@ -254,6 +280,36 @@ model Pet {
```


### `@firstLink` {#@firstLink}

Pagination property defining a link to the first page.

It is expected that the navigating to the link will return the same set of response as the operation that returned the current page.
```typespec
@firstLink
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
@nextLink next: url;
@prevLink prev: url;
@firstLink first: url;
@lastLink last: url;
}
@list op listPets(): Page<Pet>;
```


### `@format` {#@format}

Specify a known data format hint for this string type. For example `uuid`, `uri`, etc.
Expand Down Expand Up @@ -401,21 +457,49 @@ enum KnownErrorCode {
```


### `@lastLink` {#@lastLink}

Pagination property defining a link to the last page.

It is expected that the navigating to the link will return the same set of response as the operation that returned the current page.
```typespec
@lastLink
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
@nextLink next: url;
@prevLink prev: url;
@firstLink first: url;
@lastLink last: url;
}
@list op listPets(): Page<Pet>;
```


### `@list` {#@list}

Mark this operation as a `list` operation for resource types.
Mark this operation as a `list` operation that returns a paginated list of items.
```typespec
@list(listedType?: Model)
@list
```

#### Target

`Operation`

#### Parameters
| Name | Type | Description |
|------|------|-------------|
| listedType | `Model` | Optional type of the items in the list. |
None



Expand Down Expand Up @@ -613,6 +697,60 @@ scalar distance is float64;
```


### `@nextLink` {#@nextLink}
iscai-msft marked this conversation as resolved.
Show resolved Hide resolved

Pagination property defining a link to the next page.

It is expected that the navigating to the link will return the same set of response as the operation that returned the current page.
```typespec
@nextLink
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
@nextLink next: url;
@prevLink prev: url;
@firstLink first: url;
@lastLink last: url;
}
@list op listPets(): Page<Pet>;
```


### `@offset` {#@offset}

Pagination property defining the number of items to skip.
```typespec
@offset
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
}
@list op listPets(@offset skip: int32, @pageSize pageSize: int8): Page<Pet>;
```


### `@opExample` {#@opExample}

Provide example values for an operation's parameters and corresponding return type.
Expand Down Expand Up @@ -665,6 +803,78 @@ op uploadBytes(data: bytes, @header contentType: "application/octet-stream"): vo
```


### `@pageIndex` {#@pageIndex}

Pagination property defining the page index.
```typespec
@pageIndex
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
}
@list op listPets(@pageIndex page: int32, @pageSize pageSize: int8): Page<Pet>;
```


### `@pageItems` {#@pageItems}

Specify the the property that contains the array of page items.
```typespec
@pageItems
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
}
@list op listPets(@pageIndex page: int32, @pageSize pageSize: int8): Page<Pet>;
```


### `@pageSize` {#@pageSize}

Specify the pagination parameter that controls the maximum number of items to include in a page.
```typespec
@pageSize
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
}
@list op listPets(@pageIndex page: int32, @pageSize pageSize: int8): Page<Pet>;
```


### `@parameterVisibility` {#@parameterVisibility}

Sets which visibilities apply to parameters for the given operation.
Expand Down Expand Up @@ -715,6 +925,36 @@ scalar LowerAlpha extends string;
```


### `@prevLink` {#@prevLink}

Pagination property defining a link to the previous page.

It is expected that the navigating to the link will return the same set of response as the operation that returned the current page.
```typespec
@prevLink
```

#### Target

`ModelProperty`

#### Parameters
None

#### Examples

```tsp
model Page<T> {
@pageItems items: T[];
@nextLink next: url;
@prevLink prev: url;
@firstLink first: url;
@lastLink last: url;
}
@list op listPets(): Page<Pet>;
```


### `@projectedName` {#@projectedName}
:::warning
**Deprecated**: Use `@encodedName` instead for changing the name over the wire.
Expand Down
Loading
Loading