Skip to content

feat: add lazy paging with generated PagedEnumerable methods - #2332

Merged
glennawatson merged 4 commits into
mainfrom
feat/paged-generation
Sep 20, 2026
Merged

glennawatson merged 4 commits into
mainfrom
feat/paged-generation

Conversation

@glennawatson

@glennawatson glennawatson commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Summary

A Refit method can return PagedEnumerable<TPage, TItem>, and the source generator writes the paging loop.

  • PagedEnumerable<TPage, TItem> reads a paged list lazily with await foreach. It wraps a Refit method that returns one page, yields the items or the API's own page objects, and sends a fresh request per page.
  • [Paged] and [PageToken] make the generator emit the loop. [Paged] names the item and continuation members of the page, and [PageToken] marks the parameter that carries the token.
  • Cursors, offsets, response headers and next links are supported. Member names are resolved to direct property access at build time, so a misspelled name is a build error.
  • A method that follows links must state which origins a link may point at. Origins, SameOrigin or AnyOrigin decides it, and a refused link is never requested.
  • Enumeration supports early stop, WithMaxPages, WithPrefetch, cancellation of the request in flight, and observable forms. Each page is disposed as the consumer moves on.
  • IApiResponse.GetLink reads Link response headers.
  • An empty string cursor ends a cursor sequence.
  • A misconfigured paged method reports RF013.
  • Runnable examples mock S3, Azure Blob Storage, Cosmos DB, Microsoft Graph, GitHub, Google Cloud Storage, Jira and DynamoDB.
  • The Visual Studio Threading analyzers package and its inline suppressions are removed.
  • docs/breaking-changes.md gains the V16 and V15 sections.
  • CLAUDE.md describes paging and the public API baseline workflow.

Why

Every list API that returns pages makes callers hand-write the same request loop, and each service names the next page differently: S3 and Google Cloud Storage use a token in the body, Cosmos DB a header, Graph and GitHub a link, Jira an offset. There is no linked issue.

Breaking changes

None. The public API baselines only gain lines.

How this was verified

Tests cover every type this adds, the generator output and its diagnostics, and generated clients paging against a fake server. The example project runs every service scenario against local stand-ins.

Notes for the reviewer

  • Start with Parser.Paging.cs and Emitter.Inline.Paged.cs. The parser resolves the attribute members against the page type. The emitter writes a sibling request-building member plus the method that hands it to PagedEnumerable, so each page rebuilds its request.
  • Mechanical parts: the PublicAPI baselines, the generator snapshots, and the example DTOs and mocks.
  • Out of scope: the reflection request builder rejects paged returns, and the generator reports RF007 when a paged method cannot be generated inline.
  • The documentation page is in docs(refit): add the pagination page website#996.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

- Drop the package reference and its central version entry.
- Remove the inline suppressions that only existed for its rules.
- Record that the .NET 11 assemblies are built without runtime-async.
- Record that response buffering propagates caller cancellation.
- Add PagedEnumerable, a lazy sequence of items or pages over a Refit method that returns one page.
- Generate methods that return PagedEnumerable from [Paged] and [PageToken], for cursors, offsets, headers and links.
- Require an explicit origin policy before a generated method follows a next link.
- Report misconfigured paged methods as RF013.
- Add runnable examples for S3, Azure Blob Storage, Cosmos DB, Graph, GitHub, Google Cloud Storage, Jira and DynamoDB.
- Document paging and the public API baseline workflow in CLAUDE.md.
@codecov

codecov Bot commented Sep 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5106e9c) to head (3443af1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #2332    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          194       206    +12     
  Lines        10138     10805   +667     
  Branches      1947      2106   +159     
==========================================
+ Hits         10138     10805   +667     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Hand the caller's cancellation token to the async iterator instead of default.
@glennawatson
glennawatson enabled auto-merge (squash) September 20, 2026 08:52
@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit aa139a2 into main Sep 20, 2026
18 checks passed
@glennawatson
glennawatson deleted the feat/paged-generation branch September 20, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants