Skip to content

Commit 0b6a32b

Browse files
ericproulxclaude
andauthored
Stop populating the write-only namespace description in desc (#2787)
`desc` stored its settings under both the route scope (`route_setting(:description)`) and the namespace scope (`namespace_setting(:description)`). The namespace copy was never read: `route` consumes only `route[:description]`, the namespace scope is not wired for inheritance (`InheritableSetting#inherit_from` skips `@namespace`), and grape-swagger reads neither. `desc` now writes only the route scope. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 82c7cd2 commit 0b6a32b

4 files changed

Lines changed: 10 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [#2782](https://github.com/ruby-grape/grape/pull/2782): Remove the dead `format` keyword from `Grape::Router::Pattern` - [@ericproulx](https://github.com/ericproulx).
1313
* [#2783](https://github.com/ruby-grape/grape/pull/2783): Read a route's `version`, `anchor` and `requirements` from its pattern instead of storing them again on the route - [@ericproulx](https://github.com/ericproulx).
1414
* [#2784](https://github.com/ruby-grape/grape/pull/2784): Move HEAD route creation into `Grape::Router::Route#to_head` - [@ericproulx](https://github.com/ericproulx).
15+
* [#2787](https://github.com/ruby-grape/grape/pull/2787): Stop populating the write-only `namespace_setting(:description)` in `desc` - [@ericproulx](https://github.com/ericproulx).
1516
* [#2795](https://github.com/ruby-grape/grape/pull/2795): Make `Grape::Util::InheritableSetting#namespace_reverse_stackable` internal, exposing `rescue_handlers` / `base_only_rescue_handlers` / `add_rescue_handlers` instead - [@ericproulx](https://github.com/ericproulx).
1617
* [#2793](https://github.com/ruby-grape/grape/pull/2793): Add a `Grape::Mountable` marker to identify a Grape app instead of duck-typing on `respond_to?(:inheritable_setting)` - [@ericproulx](https://github.com/ericproulx).
1718
* [#2792](https://github.com/ruby-grape/grape/pull/2792): Move `Grape::Path` to `Grape::Router::Pattern::Path` and add a `Grape::Router::Pattern.build` factory (`Grape::Path` kept as a deprecated constant) - [@ericproulx](https://github.com/ericproulx).

UPGRADING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ The `:format` member was removed from the endpoint's internal `Options`. Nothing
6060

6161
`Grape::Router::Pattern#initialize` no longer accepts `format:` either. It was never given a non-`nil` value — a route's `:format` capture comes from the path suffix built by `Grape::Path`, not from the pattern — so the keyword was dead. `Grape::Router::Pattern.new(..., format: …)` now raises `unknown keyword: :format`.
6262

63+
#### `desc` no longer populates `namespace_setting(:description)`
64+
65+
`desc` used to store its settings under both the route scope (`route_setting(:description)`) and the namespace scope (`namespace_setting(:description)`). The namespace copy was write-only — the namespace scope isn't wired for inheritance and nothing in Grape or grape-swagger ever read it — so `desc` now writes only the route scope. `namespace_setting(:description)` returns `nil`; read a route's description through `route_setting(:description)` or the `route.description` reader.
6366
#### `Grape::Router::Route#params` no longer takes an argument
6467

6568
`Route#params` used to do two jobs depending on its argument: `route.params(input)` extracted param values from a matched request path, while `route.params` (no argument) returned the route's declared param definitions. These are now separate methods:

lib/grape/dsl/desc.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def desc(description, *legacy_options, **options, &config_block)
6363
else
6464
options.merge(description:)
6565
end
66-
inheritable_setting.namespace[:description] = settings
66+
# Only the route scope is consumed downstream (by +route+ and the
67+
# route's readers, e.g. +http_codes+); the namespace scope was
68+
# write-only, so it is no longer populated.
6769
inheritable_setting.route[:description] = settings
6870
end
6971
end

spec/grape/dsl/desc_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
desc_text = 'The description'
1616
options = { message: 'none' }
1717
subject.desc desc_text, **options
18-
expect(subject.namespace_setting(:description)).to eq(options.merge(description: desc_text))
1918
expect(subject.route_setting(:description)).to eq(options.merge(description: desc_text))
19+
expect(subject.namespace_setting(:description)).to be_nil
2020
end
2121

2222
context 'when a positional options Hash is passed' do
@@ -31,8 +31,8 @@
3131
Grape.deprecator.silence do
3232
subject.desc desc_text, options
3333
end
34-
expect(subject.namespace_setting(:description)).to eq(options.merge(description: desc_text))
3534
expect(subject.route_setting(:description)).to eq(options.merge(description: desc_text))
35+
expect(subject.namespace_setting(:description)).to be_nil
3636
end
3737
end
3838

@@ -103,8 +103,8 @@
103103
security %w[array of security schemes]
104104
end
105105

106-
expect(subject.namespace_setting(:description)).to eq(expected_options)
107106
expect(subject.route_setting(:description)).to eq(expected_options)
107+
expect(subject.namespace_setting(:description)).to be_nil
108108
end
109109
end
110110
end

0 commit comments

Comments
 (0)