Skip to content

Use endpoint.endpoints instead of endpoint.options[:app]#981

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

Use endpoint.endpoints instead of endpoint.options[:app]#981
ericproulx wants to merge 1 commit into
ruby-grape:masterfrom
ericproulx:use_endpoint_endpoints

Conversation

@ericproulx

@ericproulx ericproulx commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

combine_namespaces collected a mounted API's endpoints by reaching into the endpoint's options bag with endpoint.options[:app].endpoints. This switches to the first-class endpoint.endpoints reader.

- endpoints.push(*endpoint.options[:app].endpoints) if endpoint.options[:app]
+ endpoints.push(*endpoint.endpoints) if endpoint.endpoints

Why

  • Equivalent for mounted Grape APIs — endpoint.endpoints returns config.app.endpoints, exactly what options[:app].endpoints computed.
  • Safer for bare Rack (Proc) mounts: options[:app] is truthy for a Proc but has no #endpoints (would raise), whereas endpoint.endpoints is nil.
  • Works across all supported Grape versionsendpoint.endpoints has existed for a long time (verified on the 1.8 → 2.4 range and HEAD).
  • Drops the 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 :app from it; this keeps grape-swagger forward-compatible.

🤖 Generated with Claude Code

@ericproulx ericproulx force-pushed the use_endpoint_endpoints branch from 9c072c9 to dec3926 Compare July 4, 2026 10:46
`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>
@ericproulx ericproulx force-pushed the use_endpoint_endpoints branch from dec3926 to 8f356e4 Compare July 4, 2026 11:23
@github-actions

github-actions Bot commented Jul 4, 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 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].endpoints with endpoint.endpoints when collecting nested endpoints.
  • Update the relevant spec double to stub endpoints instead of options[: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
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