Read route metadata via readers instead of route.options[]#983
Open
ericproulx wants to merge 1 commit into
Open
Read route metadata via readers instead of route.options[]#983ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
Danger ReportNo issues found. |
There was a problem hiding this comment.
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.nicknameinstead ofroute.options[:nickname]. - Changed
build_body_parameterto accept a resolvedbody_namevalue 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.
numbata
approved these changes
Jul 7, 2026
46487a2 to
ca2353d
Compare
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>
ca2353d to
8b9ddff
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consume route metadata through the route's public reader methods instead of reaching into
route.options[...].What changed
Every
route.options[...]read inlib/is replaced with the equivalent reader:deprecated,security,summary,detail,produces,is_array,hidden,nickname,tags→ their readerssuccess/failure(keyword aliases ofentity/http_codes) →route.success/route.failurebody_name→ resolved by the caller asroute.body_name;build_body_parameternow takes the resolved value:formats/:content_types/:produces) →route.public_send(producer):desc/:default_response→route.desc/route.default_responseThere are no
route.options[...]reads left inlib/.Why
Grape is moving desc metadata toward first-class readers (as it already did for
params/anchor/requirements) and wants to reserveroute.optionsfor 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_objectpreviously gated onroute.options.key?(:detail); they now readroute.detail. The only observable difference is whendetail:is set explicitly tonil— it is now treated the same as an absentdetail(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 inapi_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