Skip to content

Read route metadata via readers instead of route.options[]#983

Open
ericproulx wants to merge 1 commit into
ruby-grape:masterfrom
ericproulx:route_readers_over_options
Open

Read route metadata via readers instead of route.options[]#983
ericproulx wants to merge 1 commit into
ruby-grape:masterfrom
ericproulx:route_readers_over_options

Conversation

@ericproulx

@ericproulx ericproulx commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Consume route metadata through the route's public reader methods instead of reaching into route.options[...].

What changed

Every route.options[...] read in lib/ is replaced with the equivalent reader:

  • deprecated, security, summary, detail, produces, is_array, hidden, nickname, tags → their readers
  • success / failure (keyword aliases of entity / http_codes) → route.success / route.failure
  • body_name → resolved by the caller as route.body_name; build_body_parameter now takes the resolved value
  • the dynamic producer lookup (:formats / :content_types / :produces) → route.public_send(producer)
  • grape-swagger's own :desc / :default_responseroute.desc / route.default_response

There are no route.options[...] reads left in lib/.

Why

Grape is moving desc metadata toward first-class readers (as it already did for params / anchor / requirements) and wants to reserve route.options for user custom keys. Consuming routes through their method interface means grape-swagger keeps working when Grape restructures the options bag. The readers resolve on the currently-supported Grape (verified on 2.4.0).

Behavior note (detail: nil)

summary_object / description_object previously gated on route.options.key?(:detail); they now read route.detail. The only observable difference is when detail: is set explicitly to nil — it is now treated the same as an absent detail (the description holds the text and there is no separate summary), which is the more sensible reading of "no detail". Covered by a new example in api_swagger_v2_detail_spec.rb.

Tests

Full suite: 515 examples, 2 failures (both pre-existing on master, unrelated to this change), 2 pending — no new failures. build_body_parameter's unit specs are updated for the value-based signature.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors grape-swagger’s route metadata access to use Grape’s public route reader methods (e.g., route.success, route.tags, route.body_name) instead of reaching into route.options[...], aiming to stay compatible as Grape restructures its internal options storage.

Changes:

  • Updated endpoint/document generation to consume route metadata via reader methods (including dynamic producer reads via public_send).
  • Updated OperationId generation to use route.nickname instead of route.options[:nickname].
  • Changed build_body_parameter to accept a resolved body_name value and updated specs accordingly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
spec/lib/move_params_spec.rb Updates specs for the new build_body_parameter(name, body_name) signature.
lib/grape-swagger/endpoint.rb Switches route metadata reads (tags, deprecated, security, summary/detail, produces, hidden, etc.) to reader methods.
lib/grape-swagger/doc_methods/operation_id.rb Uses route.nickname for operationId generation.
lib/grape-swagger/doc_methods/move_params.rb Passes route.body_name into build_body_parameter and updates its signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/grape-swagger/doc_methods/operation_id.rb Outdated
Comment thread lib/grape-swagger/endpoint.rb
Comment thread lib/grape-swagger/endpoint.rb
Comment thread lib/grape-swagger/endpoint.rb
Comment thread lib/grape-swagger/endpoint.rb
@ericproulx ericproulx force-pushed the route_readers_over_options branch from 46487a2 to ca2353d Compare July 8, 2026 06:25
grape-swagger reached into the route's options Hash for metadata. Replace
every route.options[...] read with the equivalent reader method —
including the success/failure aliases of entity/http_codes and the
dynamic producer lookup (via public_send) — so grape-swagger consumes
routes through their public method interface rather than the internal
options Hash. This lets Grape restructure route.options (reserving it for
user custom keys) without breaking grape-swagger.

build_body_parameter now takes a resolved body_name value rather than the
options Hash. The readers resolve on supported Grape (verified on 2.4.0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

3 participants