Skip to content

Commit 3532917

Browse files
ericproulxclaude
andcommitted
Stop populating the write-only namespace description in desc
`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 7f7b9e9 commit 3532917

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
* Your contribution here.
1617

1718
#### Fixes

UPGRADING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ 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.
66+
6367
### Upgrading to >= 3.3
6468

6569
#### Minimum required Ruby is now 3.3

lib/grape/dsl/desc.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ 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 (by +route+, for its +:params+);
67+
# the namespace scope was write-only, so it is no longer populated.
6768
inheritable_setting.route[:description] = settings
6869
end
6970
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)