Skip to content

Commit

Permalink
feat(typescript): document auto pagination (#5241)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Nov 21, 2024
1 parent 3244789 commit 5349abe
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 64 deletions.
19 changes: 19 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.42.2] - 2024-11-21

- Improvement: Added documentation for pagination in the README. The snippet below will
now show up on generated READMEs.

```typescript
// Iterate through all items
const response = await client.users.list();
for await (const item of response) {
console.log(item);
}

// Or manually paginate
let page = await client.users.list();
while (page.hasNextPage()) {
page = await page.getNextPage();
}
```


## [0.42.1] - 2024-11-20

Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.42.1
0.42.2
4 changes: 4 additions & 0 deletions generators/typescript/sdk/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ features:
description: |
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.
- id: PAGINATION
description: |
List endpoints are paginated. The SDK provides an iterator so that you can simply loop over the items:
- id: RAW_RESPONSES
advanced: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export class ReadmeConfigBuilder {
const snippets = readmeSnippetBuilder.buildReadmeSnippets();
const features: FernGeneratorCli.ReadmeFeature[] = [];
for (const feature of featureConfig.features) {
const featureSnippets = snippets[feature.id];
if (!featureSnippets) {
const snippetForFeature = snippets[feature.id];
if (snippetForFeature == null) {
continue;
}
features.push({
id: feature.id,
advanced: feature.advanced,
description: feature.description,
snippets: featureSnippets,
snippets: snippetForFeature,
snippetsAreOptional: false
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ReadmeSnippetBuilder extends AbstractReadmeSnippetBuilder {
snippets[ReadmeSnippetBuilder.ADDITIONAL_HEADERS_FEATURE_ID] = this.buildAdditionalHeadersSnippets();

if (this.isPaginationEnabled) {
snippets[ReadmeSnippetBuilder.PAGINATION_FEATURE_ID] = this.buildPaginationSnippets();
snippets[FernGeneratorCli.StructuredFeatureId.Pagination] = this.buildPaginationSnippets();
}

const requestAndResponseTypesSnippets = this.buildRequestAndResponseTypesSnippets();
Expand Down
116 changes: 57 additions & 59 deletions seed/ts-sdk/pagination/.mock/definition/users.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions seed/ts-sdk/pagination/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5349abe

Please sign in to comment.