Skip to content

fix(csharp,unity,php,ruby): keep paginating on the result length when numPages is missing or null - #187

Draft
AshGodfrey wants to merge 1 commit into
mainfrom
ash/pagination-numpages-fallback-remaining-targets
Draft

AshGodfrey wants to merge 1 commit into
mainfrom
ash/pagination-numpages-fallback-remaining-targets

Conversation

@AshGodfrey

@AshGodfrey AshGodfrey commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When an offsetLimit pagination operation declares both a numPages and a results output, the C#, Unity, PHP and Ruby SDKs ended pagination as soon as a response omitted numPages or sent it as null: C# and Unity returned null from Next(), Ruby raised NoMethodError comparing nil <= page, and PHP compared a missing path result against the page. They now stop only when numPages is numeric and <= page; otherwise they fall through to the results-length check (an empty or short page ends pagination), matching the Go, TypeScript and Python behaviour (fixed separately).

Java needed no template change: with a results output the generated paginator already uses ResultsPageTracker, which advances on the page length. This PR adds the runtime test for Java and removes its skip; the top-level Java lambda template is not rendered by the generator and is left untouched.

Behaviour change

A server that omits numPages and clamps out-of-range page numbers (keeps returning a full last page) previously stopped silently after the first page in these SDKs; it will now keep requesting pages. Such a server must return an empty or short page past the end, or state numPages.

Tests

  • New shared fragment tests/specs/fragments/uber/pagination-num-pages-missing.yaml (paginationLimitOffsetPageNumPagesMissing) and api-test-service handler /pagination/limitoffset/page/num_pages_missing: page 1 omits numPages, page 2 sends null, page 3 sends 3; limit 7, 20 items.
  • A runtime test in each target's existing primary pagination test file asserts omitted vs explicit-null numPages where the model distinguishes them (C# OptionalNullable, Java JsonNullable), the exact result arrays [0..6], [7..13], [14..19], and that no fourth page is fetched.
  • Locally, C# and Ruby fail without the template change (C#: Next() returns null after page 1; Ruby: undefined method '<=' for nil) and pass with it; Java passes. PHP relies on CI; Unity has no test runner.
  • Go, TypeScript, Python, CLI and MCP keep pagination-limit-offset-page-num-pages-missing in their skip lists until their own fix lands.

Summary by cubic

Fixes premature pagination termination in the C#, Unity, PHP, and Ruby SDKs when an offsetLimit operation declares both numPages and results outputs.

Previously, a response that omitted numPages or sent it as null ended pagination after the first page. These SDKs now only stop when numPages is numeric and <= page; otherwise, they fall back to the results-length check, matching Go, TypeScript, and Python. Java already paginated correctly through ResultsPageTracker, so it only gains the runtime test.

Behavior change

  • A server that omits numPages and keeps returning a full last page will now keep getting requested until it returns an empty or short page or states numPages.

Tests

  • Adds a shared test fragment and test-service handler serving three pages: page 1 omits numPages, page 2 sends null, page 3 sends 3.
  • Adds runtime tests to each target's existing pagination test file.
  • Go, TypeScript, Python, CLI, and MCP keep the new test in their skip lists until their own fixes land.

Written for commit 5fbcefe. Summary will update on new commits.

View guided diff Turn on auto-fix

@AshGodfrey
AshGodfrey requested a review from a team as a code owner November 3, 2026 13:22
@github-actions github-actions Bot added csharp Trigger (24) snapshot tests for csharp go Trigger (90) snapshot tests for go java Trigger (40) snapshot tests for java mcp-typescript Trigger (16) snapshot tests for mcp-typescript php Trigger (22) snapshot tests for php python Trigger (106) snapshot tests for python ruby Trigger (19) snapshot tests for ruby typescript Trigger (168) snapshot tests for typescript unity labels Nov 3, 2026
@AshGodfrey
AshGodfrey marked this pull request as draft November 3, 2026 13:23

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 20 files

Confidence score: 4/5

  • PaginationShould.cs can pass even if pagination makes an unwanted fourth HTTP request, so the test may miss a regression. Use PaginationRecorderClient and assert exactly three requests.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="templates/templates/csharp/tests/primary/PaginationShould.cs">

<violation number="1" location="templates/templates/csharp/tests/primary/PaginationShould.cs:214">
P2: This regression test does not verify that pagination avoids the fourth HTTP request: `Assert.Null(nullRes)` can pass after an unwanted page-4 fetch. Use `PaginationRecorderClient` and assert that exactly three requests were recorded.</violation>
</file>

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

public async Task PaginationLimitOffsetPageNumPagesMissing()
{
CommonHelpers.RecordTest("pagination-limit-offset-page-num-pages-missing");
var sdk = new SDK(serverUrl: Helpers.HttpBinUrl);

@cubic-dev-ai cubic-dev-ai Bot Nov 3, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This regression test does not verify that pagination avoids the fourth HTTP request: Assert.Null(nullRes) can pass after an unwanted page-4 fetch. Use PaginationRecorderClient and assert that exactly three requests were recorded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At templates/templates/csharp/tests/primary/PaginationShould.cs, line 214:

<comment>This regression test does not verify that pagination avoids the fourth HTTP request: `Assert.Null(nullRes)` can pass after an unwanted page-4 fetch. Use `PaginationRecorderClient` and assert that exactly three requests were recorded.</comment>

<file context>
@@ -207,6 +207,39 @@ public async Task PaginationLimitOffsetPageBodyNullable()
+    public async Task PaginationLimitOffsetPageNumPagesMissing()
+    {
+        CommonHelpers.RecordTest("pagination-limit-offset-page-num-pages-missing");
+        var sdk = new SDK(serverUrl: Helpers.HttpBinUrl);
+
+        // the test service omits numPages on the first page and returns null on
</file context>
Fix with cubic

… numPages is missing or null

When an offsetLimit operation declares both a numPages and a results
output, a response that omits numPages or sends it as null no longer ends
pagination. The C#, Unity, PHP and Ruby paginators now stop only on a
numeric numPages <= page and otherwise fall back to the results-length
check, matching Go, TypeScript and Python. Java already paginates on the
result length through ResultsPageTracker, so it only gains the runtime
test.
@AshGodfrey
AshGodfrey force-pushed the ash/pagination-numpages-fallback-remaining-targets branch from 846f471 to 5fbcefe Compare November 16, 2026 11:10
@speakeasy-generator-bot

speakeasy-generator-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Generator Snapshot Testing

Selector(s) Result Summary
snapshot-csharp, snapshot-go, snapshot-java, snapshot-mcp-typescript, snapshot-php, snapshot-python, snapshot-ruby, snapshot-typescript ❌ Snapshot run failed

Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/170#issuecomment-6914913004

Snapshot results are summarized above. Additional run context is linked for maintainers with access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

csharp Trigger (24) snapshot tests for csharp go Trigger (90) snapshot tests for go java Trigger (40) snapshot tests for java mcp-typescript Trigger (16) snapshot tests for mcp-typescript php Trigger (22) snapshot tests for php python Trigger (106) snapshot tests for python ruby Trigger (19) snapshot tests for ruby typescript Trigger (168) snapshot tests for typescript unity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant