Skip to content

Commit 4ec0cac

Browse files
authored
Fix Grape 3.1.0 and grape-swagger-entity 0.7.1 compatibility (#972)
* Fix Grape 3.1.0 compatibility: replace route.attributes with direct access 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 * Update RouteHelper for Grape 3.1.0 Route/Pattern constructor changes 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. * Update test expectation for hidden attributes in required list Align with grape-swagger-entity#87 which correctly excludes hidden attributes from the required fields list in Swagger documentation. * Add scheduled workflow for Grape HEAD compatibility testing Runs weekly (Sundays at midnight UTC) to detect compatibility issues with upcoming Grape releases early. * Update test for grape-swagger-entity 0.7.1 allOf wrapper 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 * Update CHANGELOG for PR #972 * Use fetch with defaults in RouteHelper to handle falsey values * Clean up: remove redundant comments, fix CHANGELOG placeholder
1 parent 85dc847 commit 4ec0cac

6 files changed

Lines changed: 65 additions & 6 deletions

File tree

.github/workflows/edge.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Edge
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0' # Every Sunday at midnight UTC
6+
workflow_dispatch: # Allow manual trigger
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
ruby: ['3.3', '3.4']
17+
name: test (ruby=${{ matrix.ruby }}, grape=HEAD)
18+
runs-on: ubuntu-latest
19+
env:
20+
GRAPE_VERSION: HEAD
21+
steps:
22+
- name: Check out branch
23+
uses: actions/checkout@v6
24+
- name: Set up Ruby
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
ruby-version: ${{ matrix.ruby }}
28+
- name: Run rspec wo model parser
29+
run: |
30+
bundle update
31+
bundle exec rspec
32+
- name: Run rspec w entity parser
33+
env:
34+
MODEL_PARSER: grape-swagger-entity
35+
run: |
36+
bundle update
37+
bundle exec rspec
38+
- name: Run rspec w representable parser
39+
env:
40+
MODEL_PARSER: grape-swagger-representable
41+
run: |
42+
bundle update
43+
bundle exec rspec

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#### Features
44

55
* [#970](https://github.com/ruby-grape/grape-swagger/pull/970): Migrate Danger to use danger-pr-comment workflow - [@dblock](https://github.com/dblock).
6+
* [#972](https://github.com/ruby-grape/grape-swagger/pull/972): Add weekly scheduled workflow to test against Grape HEAD - [@numbata](https://github.com/numbata).
7+
* Your contribution here.
8+
9+
#### Fixes
10+
11+
* [#972](https://github.com/ruby-grape/grape-swagger/pull/972): Grape 3.1.0 and grape-swagger-entity 0.7.1 compatibility - [@numbata](https://github.com/numbata).
612
* Your contribution here.
713

814
### 2.1.3 (2025-11-21)

lib/grape-swagger/endpoint.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def description_object(route)
155155
end
156156

157157
def produces_object(route, format)
158-
return ['application/octet-stream'] if file_response?(route.attributes.success) &&
159-
!route.attributes.produces.present?
158+
return ['application/octet-stream'] if file_response?(route.options[:success]) &&
159+
!route.options[:produces].present?
160160

161161
mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format)
162162

spec/issues/962_polymorphic_entity_with_custom_documentation_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ class EntityWithNestedEmptyEntity < Grape::Entity
9595
specify do
9696
expect(hidden_entity_definition).to eql({
9797
'type' => 'object',
98-
'properties' => {},
99-
'required' => ['hidden_prop']
98+
'properties' => {}
10099
})
101100
end
102101

spec/support/route_helper.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
module RouteHelper
44
def self.build(method:, pattern:, options:, origin: nil)
5-
if GrapeVersion.satisfy?('>= 2.3.0')
5+
if GrapeVersion.satisfy?('>= 3.1.0')
6+
pattern_obj = Grape::Router::Pattern.new(
7+
origin: origin || pattern,
8+
suffix: nil,
9+
anchor: options.fetch(:anchor, true),
10+
params: options.fetch(:params, {}),
11+
format: nil,
12+
version: nil,
13+
requirements: options.fetch(:requirements, {})
14+
)
15+
Grape::Router::Route.new(nil, method, pattern_obj, options)
16+
elsif GrapeVersion.satisfy?('>= 2.3.0')
617
Grape::Router::Route.new(method, origin || pattern, pattern, options)
718
else
819
Grape::Router::Route.new(method, pattern, **options)

spec/swagger_v2/reference_entity_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def app
101101
'properties' => {
102102
'title' => { 'type' => 'string', 'description' => 'Title of the kind.' },
103103
'something' => {
104-
'$ref' => '#/definitions/SomethingCustom',
104+
'allOf' => [{ '$ref' => '#/definitions/SomethingCustom' }],
105105
'description' => 'Something interesting.'
106106
}
107107
},

0 commit comments

Comments
 (0)