Repository navigation
refactor: parse list pagination params in one Pagination concern - #21
Open
dex-the-ai wants to merge 1 commit into
Open
dex-the-ai wants to merge 1 commit into
dex-the-ai wants to merge 1 commit into
Conversation
The airlines list, airlines to-airport and airports direct-connections actions each read params[:limit]/params[:offset] with their own defaults and passed the raw strings to N1QL query_fns that interpolate them into LIMIT/OFFSET. Non-integer values were parsed as N1QL expressions (500 with the statement echoed back), and negative values returned []. Pagination#pagination_params now owns the defaults (10/0) and returns non-negative Integers, raising ArgumentError (rendered as 400 by the existing rescues) otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Three list endpoints each parsed
limit/offsetthemselves and handed the raw query-string values to N1QLquery_fns, which interpolate them intoLIMIT #{values[1]} OFFSET #{values[2]}. This PR moves that parsing into onePaginationconcern, which owns the defaults and makes sure only non-negative Integers reach the models.app/controllers/ +├── concerns/pagination.rb # pagination_params -> [limit, offset] (Integers, defaults 10/0) └── api/v1/ ├── airlines_controller.rb # index, to_airport: include Pagination └── airports_controller.rb # direct_connections: include PaginationSwagger already documents both parameters as
type: integer, so the API now enforces its own documented contract.Evidence
Tested live against a local Couchbase 8.0.3 with
travel-sample, runningrails s -e testinruby:3.4.1:airlines/list?country=France&limit=2airlines/list?...&limit=abc3080: Ambiguous reference to field 'abc', with the full statement echoed backlimit must be a non-negative integerairlines/to-airport?...&limit=-1[]...&limit=2 UNION SELECT RAW 'pwned'parsing_failure, with the statement echoed backbundle exec rspec spec/requests/api/v1:limit: '10 OFFSET 0'on direct-connections.CI=true rake rswag:specs:swaggerize: 63 examples, 0 failures.rubocop app/controllers spec/requests/api/v1: 48 offenses before, 47 after. The new file has none.Merge Danger
Door: two-way. It's controller-only with no data or schema changes, so a revert is enough to undo it.
Blast Radius: small. The only change clients see is that
limit/offsetvalues that aren't non-negative integers now get a 400 with a clear message, where before they got a 500 or an empty list. Valid and omitted values behave exactly as before.Follow-ups, not in this PR:
GET /api/v1/airports/listcomputespage/per_page/offsetand then never uses them, so it returns every airport.routes_specPOST test isn't idempotent. A run that dies mid-way leavesroute_postbehind, and the next run gets a 409.indexandto_airport.🤖 Generated with Claude Code