Use endpoint.endpoints instead of endpoint.options[:app]#981
Open
ericproulx wants to merge 1 commit into
Open
Conversation
9c072c9 to
dec3926
Compare
`combine_namespaces` reached into the endpoint's options bag with `endpoint.options[:app].endpoints` to collect a mounted API's endpoints. Use the `endpoint.endpoints` reader instead, which returns exactly those endpoints for a mounted Grape API (and `nil` otherwise). This is equivalent for Grape mounts, works across all supported Grape versions, and is safer for bare Rack (Proc) mounts — `options[:app]` is truthy for a Proc but has no `#endpoints`, whereas `endpoint.endpoints` is `nil`. It also drops grape-swagger's dependency on `options[:app]`, which Grape plans to remove from the endpoint options Hash. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dec3926 to
8f356e4
Compare
Danger ReportNo issues found. |
There was a problem hiding this comment.
Pull request overview
This pull request updates how mounted API endpoints are discovered in combine_namespaces, switching from reaching into an endpoint’s options hash (endpoint.options[:app]) to using the first-class endpoint.endpoints reader to improve forward-compatibility with Grape and avoid errors on bare Rack mounts.
Changes:
- Replace
endpoint.options[:app].endpointswithendpoint.endpointswhen collecting nested endpoints. - Update the relevant spec double to stub
endpointsinstead ofoptions[:app]. - Add a changelog entry describing the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/grape-swagger/swagger_documentation_adder.rb | Use endpoint.endpoints to safely and directly collect nested endpoints during namespace combination. |
| spec/lib/swagger_routing_spec.rb | Adjust test setup to match the new endpoint.endpoints access pattern. |
| CHANGELOG.md | Document the change under upcoming fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| endpoint = endpoints.shift | ||
|
|
||
| endpoints.push(*endpoint.options[:app].endpoints) if endpoint.options[:app] | ||
| endpoints.push(*endpoint.endpoints) if endpoint.endpoints |
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.
Summary
combine_namespacescollected a mounted API's endpoints by reaching into the endpoint's options bag withendpoint.options[:app].endpoints. This switches to the first-classendpoint.endpointsreader.Why
endpoint.endpointsreturnsconfig.app.endpoints, exactly whatoptions[:app].endpointscomputed.Proc) mounts:options[:app]is truthy for aProcbut has no#endpoints(would raise), whereasendpoint.endpointsisnil.endpoint.endpointshas existed for a long time (verified on the 1.8 → 2.4 range and HEAD).options[:app]dependency. Grape is moving endpoint attributes out of the catch-all options Hash toward named accessors (http_methods,path,mounted_app, …) and plans to remove:appfrom it; this keeps grape-swagger forward-compatible.🤖 Generated with Claude Code