Skip to content

Make route params a first-class endpoint input and split Route#params#2785

Open
ericproulx wants to merge 1 commit into
masterfrom
untangle_route_params
Open

Make route params a first-class endpoint input and split Route#params#2785
ericproulx wants to merge 1 commit into
masterfrom
untangle_route_params

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

Grape::Router::Route#params(input = nil) did two unrelated jobs behind one signature:

Caller Call Wanted
the router (router.rb) route.params(input) extracted param values from the matched path
grape-swagger (production) route.params (no arg) declared param definitions, keyed by name

One method, two consumers, two incompatible return shapes. This splits them and, along the way, lifts params out of the route_options bag.

Split

  • Route#params (no arg) → the declared definitions (grape-swagger, unchanged).
  • Route#params_for(input) → extracted values; router.rb calls this.

params as a first-class endpoint input

Previously params lived inside the route_options bag. Now:

  • Grape::Endpoint::Options gains a :params member; Grape::Endpoint.new gains a params: keyword.
  • The DSL composes params — declared params (params do … end) deep-merged with any documented alongside desc …, params: — via a prepare_params helper, and passes it as its own input.
  • Endpoint#to_routes and #declared read config.params; Route receives it as a params: keyword backing #params.

The composition (declared ⊕ desc params) is preserved exactly; only its home changes. Nothing outside grape read route.options[:params] — grape-swagger gets params through the route.params method — so dropping it from the bag is safe.

Upgrading

  • Grape::Router::Route#params no longer accepts an argument — use #params_for(input) to extract values from a path. The no-arg form (declared definitions) is unchanged.
  • params no longer appears in route.options (nor the endpoint's route_options); it's config.params.
  • Grape::Endpoint.new gains a params: keyword and Grape::Endpoint::Options a :params member.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

`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>
@ericproulx ericproulx force-pushed the untangle_route_params branch from 21695b8 to 2e21378 Compare July 6, 2026 09:57
@ericproulx ericproulx requested a review from dblock July 6, 2026 10:17
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.

1 participant