Make route params a first-class endpoint input and split Route#params#2785
Open
ericproulx wants to merge 1 commit into
Open
Make route params a first-class endpoint input and split Route#params#2785ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
Danger ReportNo issues found. |
cf43c66 to
21695b8
Compare
`Route#params(input = nil)` did two unrelated jobs behind one signature: with an input it extracted param values from a matched path (the router's job); with no input it returned the declared param definitions (grape- swagger's job, for docs). Split them: - `Route#params` (no arg) returns the declared definitions. - `Route#params_for(input)` extracts values; the router calls it. The definitions also stop riding in the `route_options` bag. `params` is now a first-class endpoint input: - `Grape::Endpoint::Options` gains a `:params` member and `Endpoint.new` a `params:` keyword. - The DSL composes it (declared params deep-merged with any from `desc`) via a `prepare_params` helper and passes it on its own, out of `route_options`. - `to_routes` and `#declared` read `config.params`; `Route` receives it as a `params:` keyword backing `#params`. Nothing outside grape read `route.options[:params]` (grape-swagger uses the `route.params` method), so dropping it from the bag is safe. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
21695b8 to
2e21378
Compare
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.
Grape::Router::Route#params(input = nil)did two unrelated jobs behind one signature:router.rb)route.params(input)route.params(no arg)One method, two consumers, two incompatible return shapes. This splits them and, along the way, lifts
paramsout of theroute_optionsbag.Split
Route#params(no arg) → the declared definitions (grape-swagger, unchanged).Route#params_for(input)→ extracted values;router.rbcalls this.paramsas a first-class endpoint inputPreviously
paramslived inside theroute_optionsbag. Now:Grape::Endpoint::Optionsgains a:paramsmember;Grape::Endpoint.newgains aparams:keyword.params— declared params (params do … end) deep-merged with any documented alongsidedesc …, params:— via aprepare_paramshelper, and passes it as its own input.Endpoint#to_routesand#declaredreadconfig.params;Routereceives it as aparams:keyword backing#params.The composition (declared ⊕
descparams) is preserved exactly; only its home changes. Nothing outside grape readroute.options[:params]— grape-swagger gets params through theroute.paramsmethod — so dropping it from the bag is safe.Upgrading
Grape::Router::Route#paramsno longer accepts an argument — use#params_for(input)to extract values from a path. The no-arg form (declared definitions) is unchanged.paramsno longer appears inroute.options(nor the endpoint'sroute_options); it'sconfig.params.Grape::Endpoint.newgains aparams:keyword andGrape::Endpoint::Optionsa:paramsmember.🤖 Generated with Claude Code