Added cursor pagination support to paged operations.
This commit is contained in:
1 parent
fde2382056
commit
c984be3263
7 files changed
+4340
-4
No files matched your search
@@ -42,6 +42,21 @@ let apps = try response.ok.body.json.data
|
||||
|
||||
The `ok` property throws for any other response. To handle those, switch over the `Output` cases, such as `.unauthorized` or `.undocumented(statusCode:_:)`.
|
||||
|
||||
### Fetching More Pages
|
||||
|
||||
Lists are paged. Pass a page's ``Components/Schemas/PagedDocumentLinks/nextCursor`` as the `cursor` of the next request:
|
||||
|
||||
```swift
|
||||
var apps: [Components.Schemas.App] = []
|
||||
var cursor: String?
|
||||
|
||||
repeat {
|
||||
let page = try await client.appsGetCollection(query: .init(limit: 200, cursor: cursor)).ok.body.json
|
||||
apps += page.data
|
||||
cursor = page.links.nextCursor
|
||||
} while cursor != nil
|
||||
```
|
||||
|
||||
## Topics
|
||||
|
||||
### API Client
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the ASConnectService open source project
|
||||
//
|
||||
// Copyright (c) 2026 Röck+Cöde VoF. and the ASConnectService project authors
|
||||
// Licensed under Apache license v2.0
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of ASConnectService project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import struct Foundation.URLComponents
|
||||
|
||||
extension Components.Schemas.PagedDocumentLinks {
|
||||
// MARK: Properties
|
||||
|
||||
/// The cursor of the next page, or `nil` on the last page.
|
||||
///
|
||||
/// Pass it as the `cursor` query parameter of the same operation to fetch the next page.
|
||||
public var nextCursor: String? {
|
||||
guard let next else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return URLComponents(string: next)?
|
||||
.queryItems?
|
||||
.first { $0.name == "cursor" }?
|
||||
.value
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user