Skip to content

Fix Grape 3.1.0 and grape-swagger-entity 0.7.1 compatibility#972

Merged
dblock merged 8 commits intomasterfrom
fix/grape-3.1.0-compatibility
Jan 29, 2026
Merged

Fix Grape 3.1.0 and grape-swagger-entity 0.7.1 compatibility#972
dblock merged 8 commits intomasterfrom
fix/grape-3.1.0-compatibility

Conversation

@numbata
Copy link
Contributor

@numbata numbata commented Jan 27, 2026

Summary

Grape 3.1.0 refactored BaseRoute to remove the attributes alias, causing NoMethodError when generating swagger documentation. This PR fixes the compatibility issue by accessing route options directly via route.options[:success] and route.options[:produces], which works consistently across all Grape versions.

Additionally, this PR updates test expectations to align with grape-swagger-entity 0.7.1, which introduced two behavioral changes:

A weekly scheduled workflow has been added to catch future compatibility issues with Grape HEAD early.

Test plan

All tests pass across the full matrix: Ruby 3.1-3.4 + head, Grape 1.8.0-HEAD, with and without grape-swagger-entity parser.

Fixes #971

@numbata numbata linked an issue Jan 27, 2026 that may be closed by this pull request
@numbata numbata force-pushed the fix/grape-3.1.0-compatibility branch from d18b5ec to 59fe9c1 Compare January 28, 2026 00:02
@github-actions
Copy link

github-actions bot commented Jan 28, 2026

Danger Report

No issues found.

View run

…ccess

Grape 3.1.0 removed the `attributes` alias from BaseRoute.
Use direct method calls (route.success, route.produces) which work
in all versions via delegate_missing_to.

Fixes #971
Grape 3.1.0 changed the Route constructor signature from
(method, origin, path, options) to (endpoint, method, pattern, options)
and Pattern now uses keyword arguments.
Align with grape-swagger-entity#87 which correctly excludes hidden
attributes from the required fields list in Swagger documentation.
Runs weekly (Sundays at midnight UTC) to detect compatibility
issues with upcoming Grape releases early.
@numbata numbata force-pushed the fix/grape-3.1.0-compatibility branch from 59fe9c1 to 6cc8961 Compare January 28, 2026 00:11
grape-swagger-entity 0.7.1 now wraps $ref in allOf when description
is present, which is the correct OpenAPI format.

See: ruby-grape/grape-swagger-entity#90
@numbata numbata requested a review from Copilot January 28, 2026 20:35
@numbata numbata self-assigned this Jan 28, 2026
@numbata numbata changed the title Fix Grape 3.1.0 compatibility Fix Grape 3.1.0 and grape-swagger-entity 0.7.1 compatibility Jan 28, 2026
Copy link

Copilot AI left a comment

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 fixes compatibility issues with Grape 3.1.0, which introduced breaking changes by removing the route.attributes method and changing constructor signatures for Route and Pattern classes.

Changes:

  • Fixed route.attributes removal by using route.options hash directly
  • Updated test helper to support new Grape 3.1.0 Route/Pattern constructor signatures with backward compatibility
  • Aligned tests with grape-swagger-entity#87 changes regarding hidden attributes and reference formatting

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/grape-swagger/endpoint.rb Replaced deprecated route.attributes.success and route.attributes.produces with route.options[:success] and route.options[:produces]
spec/support/route_helper.rb Added Grape 3.1.0+ support with new Route/Pattern constructor signatures using keyword arguments
spec/swagger_v2/reference_entity_spec.rb Updated test expectation to reflect grape-swagger-entity's new behavior of wrapping $ref in allOf
spec/issues/962_polymorphic_entity_with_custom_documentation_spec.rb Removed required array from hidden entity definition test to align with grape-swagger-entity#87
.github/workflows/edge.yml Added weekly scheduled workflow to test against Grape HEAD to catch future compatibility issues early

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

@numbata numbata requested a review from LeFnord January 28, 2026 20:39
@numbata numbata requested a review from dblock January 28, 2026 20:41
@dblock dblock merged commit 4ec0cac into master Jan 29, 2026
23 checks passed
@dblock dblock deleted the fix/grape-3.1.0-compatibility branch January 29, 2026 00:32
@totus
Copy link

totus commented Feb 2, 2026

@dblock, apologies for bugging, is this going to be released (as 2.1.4?) any time soon?
Thanks in advance!

@numbata
Copy link
Contributor Author

numbata commented Feb 2, 2026

@totus I plan on doing that this evening, unless @dblock does it first.

@numbata
Copy link
Contributor Author

numbata commented Feb 3, 2026

@totus thanks for your patience! The new gem version has been released: https://rubygems.org/gems/grape-swagger/versions/2.1.4

@totus
Copy link

totus commented Feb 3, 2026

@numbata, thanks a lot, extremely appreciated!

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.

Grape 3.1.0 breaks compatibility w/ grape-swagger 2.1.3

3 participants