You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`version`, `namespace`, `prefix`, `requirements`, `anchor` and `settings`
were computed in `Endpoint#prepare_default_route_attributes`, merged into
the route options Hash, and read back through `Grape::Router::BaseRoute`'s
`def_delegators :@options`. They are route metadata, not part of the
user-declared options bag grape-swagger consumes.
They are now passed to `Grape::Router::Route` as explicit keyword
arguments and exposed as plain readers on `BaseRoute`. `Endpoint#to_routes`
computes each as a local and passes `config.route_options` straight
through, so `prepare_default_route_attributes` (and the intermediate
`default_route_options`/`complete_route_options`) is gone. `Route`
forwards the attributes to `super` via `**route_attributes` to keep its
signature lean.
`route.options` now carries only what was declared for the route; the
`@options` delegation is down to `description` plus the documentation
`DSL_METHODS`. The readers are unchanged, so grape-swagger (which reads
`route.prefix` and `route.settings`) is unaffected. `requirements` and
`anchor` can still be declared as route options, so any explicit value
stays in `route.options`; the effective value comes from the reader.
Also drop the vestigial `:format` member from the endpoint's `Options`.
Nothing ever passed `format:` to `Grape::Endpoint.new`, so `config.format`
was always `nil`; the format capture comes from the path suffix built by
`Grape::Path`, not from `Pattern`'s `format`. `Pattern#initialize` keeps
`format:` (now optional) since it remains a valid capture constraint used
by external callers.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@
8
8
*[#2776](https://github.com/ruby-grape/grape/pull/2776): Pass `path` to `Grape::Endpoint` as a keyword instead of via options - [@ericproulx](https://github.com/ericproulx).
9
9
*[#2777](https://github.com/ruby-grape/grape/pull/2777): Add `Grape::Endpoint#mounted_app` reader and `app:` keyword - [@ericproulx](https://github.com/ericproulx).
10
10
*[#2778](https://github.com/ruby-grape/grape/pull/2778): Rename `Grape::Endpoint`'s `for:` keyword to `api:` and expose `#api` - [@ericproulx](https://github.com/ericproulx).
The owning API is no longer carried on the endpoint's public `options` Hash — `endpoint.options[:for]` is gone. Use the new `endpoint.api` reader instead.
39
39
40
+
#### Route metadata is exposed through readers, not the `options` Hash
41
+
42
+
A route's computed metadata — `version`, `namespace`, `prefix`, `requirements`, `anchor` and `settings` — is now passed to `Grape::Router::Route` as explicit keyword arguments and exposed as plain readers, instead of being merged into the route's `options` Hash.
43
+
44
+
The readers are unchanged — keep using them:
45
+
46
+
```ruby
47
+
route.version # => 'v1'
48
+
route.namespace # => '/things'
49
+
route.prefix # => 'api'
50
+
route.requirements # => {}
51
+
route.anchor # => true
52
+
route.settings # => { ... }
53
+
```
54
+
55
+
What changed is the raw bag. `route.options` now holds only what was declared for the route, so it no longer carries the *computed* values for these keys — `route.options[:version]`, `[:namespace]`, `[:prefix]` and `[:settings]` return `nil`. Nothing in Grape or grape-swagger read them that way (grape-swagger uses the `route.prefix` and `route.settings` readers). For `requirements` and `anchor`, which can be supplied as route options (e.g. a mount's `anchor: false`), any explicitly declared value still appears in `route.options`; the effective value always comes from the reader.
0 commit comments