Skip to content

feat: paging yields what an API lists a page at a time - #7

Merged
MarkRosemaker merged 2 commits into
masterfrom
feat/page
Nov 15, 2026
Merged

MarkRosemaker merged 2 commits into
masterfrom
feat/page

Conversation

@MarkRosemaker

@MarkRosemaker MarkRosemaker commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

A new package, paging, which the iterators openapi-codegen will generate for paginated lists rest on. No library then writes its own.

// each page, fetched by cursor (the zero cursor first) as the one before is used up
func Pages[P any, C comparable](fetch func(cursor C) (P, error), next func(P) (C, bool)) iter.Seq2[P, error]

// the items of each page
func Items[P, T any](pages iter.Seq2[P, error], items func(P) []T) iter.Seq2[T, error]

Both stop when the loop breaks, and at the first error, which they yield once. The cursor type is generic, so a UUID cursor stays a UUID and a named string stays its own type. A generated ListCommentsPages is one call to paging.Pages, and ListCommentsAll one call to paging.Items over it.

Why paging and not page. Generated code imports it into an API's own package. Such packages often declare a page of their own, and an import named page collides with any package-level page. codegen's golden build caught that.

It's the same logic as notion's hand-written all, which it will replace. The tests cover paging, breaking out at the first item and at the first page, and an error after some items, at 100% coverage. The README now names union, apitest and paging.

make ready passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y

page.Pages yields each page of a list, fetched by cursor as the one before is
used up, and page.Items the items of each: both stop when the loop breaks and
at the first error, which they yield. They are what the iterators
openapi-codegen will generate for a list rest on, so no library writes its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
…ge does not collide with

Generated code imports it into packages of APIs, which often declare a page of
their own, as Notion's does: an import named page collides with any page
declared at package level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
@MarkRosemaker MarkRosemaker changed the title feat: page yields what an API lists a page at a time feat: paging yields what an API lists a page at a time Nov 15, 2026
@MarkRosemaker
MarkRosemaker merged commit 02c29b6 into master Nov 15, 2026
1 check passed
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