Skip to content

fix: Add empty string cursor support for pagination endpoint#33

Merged
GorshkovIvan merged 3 commits into
mainfrom
ivan/empty-strings-pagination-endpoint
Aug 28, 2025
Merged

fix: Add empty string cursor support for pagination endpoint#33
GorshkovIvan merged 3 commits into
mainfrom
ivan/empty-strings-pagination-endpoint

Conversation

@GorshkovIvan

Copy link
Copy Markdown

Add empty string cursor support for pagination endpoint

This PR adds support for returning an empty string cursor in the non-numeric cursor pagination endpoint when the endCursor parameter
is set to #emptyString.

Changes:

  • Refactored HandleNonNumericCursor to accept an endCursor parameter
  • Added logic to handle the special #emptyString value by setting an empty string cursor
  • Maintains backward compatibility with existing pagination behavior

The change is needed to test for bugs described here: https://linear.app/speakeasy/issue/GEN-1759/bug-empty-cursor-values-not-properly-handled-for-termination

@GorshkovIvan GorshkovIvan self-assigned this Aug 22, 2025
Comment thread internal/pagination/service.go Outdated

@2ynn 2ynn 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.

lgtm! minor comment only

Comment thread internal/pagination/service.go Outdated
if ok && len(vals) > 0 {
endCursor = &vals[0]
}
handleNonNumericCursorWithEndCursor(w, r, endCursor)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wonder if it's really necessary to have a separate helper function

Comment on lines 267 to 272
if len(res.ResultArray) == limit {
cursor, _ := res.ResultArray[len(res.ResultArray)-1].(string)
res.Cursor = &cursor
} else if endCursor != nil {
res.Cursor = endCursor
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If len(res.ResultArray) == limit && endCursor != nil then we will always fall in the first condition. Is that fine ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, we iterate until hit the condition where the page is not full and only then return empty cursor @kanwardeep007

@GorshkovIvan GorshkovIvan changed the title fix: Add empty string cursor support for pagination endpoint* fix: Add empty string cursor support for pagination endpoint Aug 27, 2025
@GorshkovIvan
GorshkovIvan merged commit b7bf47c into main Aug 28, 2025
2 checks 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.

3 participants