Skip to content

Commit 3e842a1

Browse files
authored
Dependencies update (#948)
* Add spec route helper to complain with Grape >= 2.3.0 * Explicitly add ostruct gem in case of Ruby 3.5 * Update CHANGELOG
1 parent 599712e commit 3e842a1

File tree

6 files changed

+19
-4
lines changed

6 files changed

+19
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* your contribution
10+
* [#948](https://github.com/ruby-grape/grape-swagger/pull/948): Grape 2.3.0 and Ruby 3.5 compatibility - [@numbata](https://github.com/numbata)
1011

1112

1213
### 2.1.2 (Jan 7, 2025)

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ group :development, :test do
3737
unless ENV['MODEL_PARSER'] == 'grape-swagger-entity'
3838
gem 'grape-swagger-entity', git: 'https://github.com/ruby-grape/grape-swagger-entity'
3939
end
40+
41+
# Conditionally load 'ostruct' only if Ruby >= 3.5.0
42+
gem 'ostruct' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.5.0')
4043
end
4144

4245
group :test do

lib/grape-swagger/endpoint.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def content_types_for(target_class)
1212
if content_types.empty?
1313
formats = [target_class.format, target_class.default_format].compact.uniq
1414
formats = GrapeSwagger::FORMATTER_DEFAULTS.keys if formats.empty?
15-
content_types = GrapeSwagger::CONTENT_TYPE_DEFAULTS.select do |content_type, _mime_type|
15+
content_types = GrapeSwagger::CONTENT_TYPE_DEFAULTS.select do |content_type, _mime_type| # rubocop:disable Style/HashSlice
1616
formats.include? content_type
1717
end.values
1818
end

spec/lib/move_params_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
let(:route_options) { { requirements: {} } }
9898
describe 'POST' do
9999
let(:params) { paths[path][:post][:parameters] }
100-
let(:route) { Grape::Router::Route.new('POST', path.dup, **route_options) }
100+
let(:route) { RouteHelper.build(method: 'POST', pattern: path.dup, options: route_options) }
101101

102102
specify do
103103
subject.to_definition(path, params, route, definitions)
@@ -128,7 +128,7 @@
128128

129129
describe 'PUT' do
130130
let(:params) { paths['/in_body/{key}'][:put][:parameters] }
131-
let(:route) { Grape::Router::Route.new('PUT', path.dup, **route_options) }
131+
let(:route) { RouteHelper.build(method: 'PUT', pattern: path.dup, options: route_options) }
132132

133133
specify do
134134
subject.to_definition(path, params, route, definitions)

spec/lib/operation_id_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
specify { expect(subject).to respond_to :build }
1010

1111
describe 'build' do
12-
let(:route) { Grape::Router::Route.new(method, '/path', requirements: {}) }
12+
let(:route) { RouteHelper.build(method: method, pattern: '/path', options: { requirements: {} }) }
1313

1414
describe 'GET' do
1515
let(:method) { 'GET' }

spec/support/route_helper.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module RouteHelper
4+
def self.build(method:, pattern:, options:, origin: nil)
5+
if GrapeVersion.satisfy?('>= 2.3.0')
6+
Grape::Router::Route.new(method, origin || pattern, pattern, options)
7+
else
8+
Grape::Router::Route.new(method, pattern, **options)
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)