Skip to content

Stop populating the write-only namespace description in desc#2787

Merged
dblock merged 2 commits into
masterfrom
drop_namespace_description
Jul 14, 2026
Merged

Stop populating the write-only namespace description in desc#2787
dblock merged 2 commits into
masterfrom
drop_namespace_description

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

desc wrote its settings into two places — the route scope (route_setting(:description)) and the namespace scope (namespace_setting(:description)) — but the namespace copy was pure dead state:

  • Grape's runtime reads only route[:description] (in route(), and only for the :params key).
  • The namespace scope isn't wired for inheritance — InheritableSetting#inherit_from sets inherited_values for namespace_inheritable/namespace_stackable/namespace_reverse_stackable and merges route, but never touches @namespace. So namespace-scope values are only cloned by point_in_time_copy and never consulted.
  • grape-swagger doesn't read it either (checked against the local checkout).

Confirmed by experiment: dropping the write breaks only the desc_spec.rb assertions that checked the write itself — the rest of the suite is unaffected.

Change

desc now writes only the route scope. namespace_setting(:description) returns nil; a route's description remains available via route_setting(:description) and the route.description reader. UPGRADING note added.

Full suite green (2351 examples, 0 failures); RuboCop clean.

🤖 Generated with Claude Code

@ericproulx ericproulx force-pushed the drop_namespace_description branch from 22c44e2 to 3532917 Compare July 6, 2026 12:35
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@ericproulx ericproulx requested a review from dblock July 6, 2026 12:40
`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>
@ericproulx ericproulx force-pushed the drop_namespace_description branch from 3532917 to 9b6eeae Compare July 6, 2026 12:44
@dblock

dblock commented Jul 12, 2026

Copy link
Copy Markdown
Member

Can a namespace have its own/different description?

@ericproulx

Copy link
Copy Markdown
Contributor Author

No — and it couldn't before this PR either. desc has only ever described the next endpoint: the runtime consumes only route[:description], and the namespace-scope copy removed here was write-only (the @namespace scope isn't wired into inherit_from, and neither Grape nor grape-swagger ever read it).

What desc before a namespace actually does is unchanged by this PR — it attaches to the first route defined inside (verified against this branch):

desc 'namespace-level description'
namespace :users do
  get :first   # description: "namespace-level description"

  desc 'route-level description'
  get :second  # "route-level description"

  get :third   # nil
end

So routes inside a namespace can each have their own description, exactly as before. For metadata on the namespace itself, the supported channel is options on the namespace call — namespace :users, desc: 'User operations' — which land in Grape::Namespace#options and are what grape-swagger walks via namespace_stackable[:namespace].

(Side note: an unconsumed desc also leaks into the first route of the next sibling namespace — a pre-existing quirk, untouched here; happy to open a follow-up issue.)

@dblock

dblock commented Jul 14, 2026

Copy link
Copy Markdown
Member

An unconsumed desc also leaks into the first route of the next sibling namespace — a pre-existing quirk, untouched here; happy to open a follow-up issue.

Yes, this looks unexpected. I think desc on a namespace should cause an error.

@dblock dblock merged commit 0b6a32b into master Jul 14, 2026
75 of 171 checks passed
@dblock dblock deleted the drop_namespace_description branch July 14, 2026 01:23
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.

2 participants