fix(pagination): iterator paged whichever array the spec declared first - #66
Open
giraffesyo wants to merge 1 commit into
Open
fix(pagination): iterator paged whichever array the spec declared first#66giraffesyo wants to merge 1 commit into
giraffesyo wants to merge 1 commit into
Conversation
A page type with no field named items, data, or results fell back to the first array-typed field, so a response holding warnings alongside events produced an iterator over the warnings. It compiled, it ran, and it returned the wrong data, decided by property order in the spec. An array is now the page when its name says so, when it is the only array, or when it is the only array of a declared type beside arrays of scalars. Two arrays of records identify nothing, and the operation gets no iterator rather than a guess: the plain method still returns the whole page. The iterator also stops when the cursor comes back unchanged. A response field named cursor is as often the echo of the request cursor as the next one, and All() turned that into an endless run of identical requests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #65.
The iterator could page the wrong array
findItemsFieldfell back to the first array-typed field when no field was nameditems,data, orresults:It compiled, it ran, and it returned the wrong data. Which array won was decided by property order in the spec.
An array is the page when one of three things holds:
items,data, orresults, as before,Rule 3 is what keeps the case above working, and it now yields
PageIterator[Event]overresult.Events. Two arrays of records identify nothing, and there the operation gets no iterator at all. That is not a loss: the plainListEventsmethod still returns the whole page, and an iterator over the wrong field is worse than no iterator.The iterator could loop forever
cursorFieldNamesincludes barecursor, and in a response that is as often the echo of the request cursor as the next one.Nextstopped only on an empty cursor, so an echoing server turnedAll()into an endless run of identical requests.A cursor that does not advance means the page did not advance, whatever the field is called, so this also covers a server that pins its cursor on the last page rather than clearing it. Bare
cursorstays in the name list: APIs do use it correctly, and the guard bounds the damage when they do not.Tests
internal/analyzer/pagination_test.go: conventional name wins, lone array is the page, record array beats scalar arrays, two record arrays get no iterator, no array gets no iterator.internal/generator/e2e_pagination_test.go: compiles and runs the generated iterator against a fetch that always returns the same cursor, asserting it stops after the repeat, and against an advancing cursor, asserting it still pages to the end and sends each cursor in turn.gofmt,go vet ./..., andgo test ./...pass.