diff --git a/CHANGELOG.md b/CHANGELOG.md index c54b36a5..1d7bc202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ #### Fixes * your contribution +* [#948](https://github.com/ruby-grape/grape-swagger/pull/948): Grape 2.3.0 and Ruby 3.5 compatibility - [@numbata](https://github.com/numbata) ### 2.1.2 (Jan 7, 2025) diff --git a/Gemfile b/Gemfile index c5ddc597..ebfe7cf5 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,9 @@ group :development, :test do unless ENV['MODEL_PARSER'] == 'grape-swagger-entity' gem 'grape-swagger-entity', git: 'https://github.com/ruby-grape/grape-swagger-entity' end + + # Conditionally load 'ostruct' only if Ruby >= 3.5.0 + gem 'ostruct' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.5.0') end group :test do diff --git a/lib/grape-swagger/endpoint.rb b/lib/grape-swagger/endpoint.rb index 15509be5..1c4274f0 100644 --- a/lib/grape-swagger/endpoint.rb +++ b/lib/grape-swagger/endpoint.rb @@ -12,7 +12,7 @@ def content_types_for(target_class) if content_types.empty? formats = [target_class.format, target_class.default_format].compact.uniq formats = GrapeSwagger::FORMATTER_DEFAULTS.keys if formats.empty? - content_types = GrapeSwagger::CONTENT_TYPE_DEFAULTS.select do |content_type, _mime_type| + content_types = GrapeSwagger::CONTENT_TYPE_DEFAULTS.select do |content_type, _mime_type| # rubocop:disable Style/HashSlice formats.include? content_type end.values end diff --git a/spec/lib/move_params_spec.rb b/spec/lib/move_params_spec.rb index bd294e45..f0528ac5 100644 --- a/spec/lib/move_params_spec.rb +++ b/spec/lib/move_params_spec.rb @@ -97,7 +97,7 @@ let(:route_options) { { requirements: {} } } describe 'POST' do let(:params) { paths[path][:post][:parameters] } - let(:route) { Grape::Router::Route.new('POST', path.dup, **route_options) } + let(:route) { RouteHelper.build(method: 'POST', pattern: path.dup, options: route_options) } specify do subject.to_definition(path, params, route, definitions) @@ -128,7 +128,7 @@ describe 'PUT' do let(:params) { paths['/in_body/{key}'][:put][:parameters] } - let(:route) { Grape::Router::Route.new('PUT', path.dup, **route_options) } + let(:route) { RouteHelper.build(method: 'PUT', pattern: path.dup, options: route_options) } specify do subject.to_definition(path, params, route, definitions) diff --git a/spec/lib/operation_id_spec.rb b/spec/lib/operation_id_spec.rb index 42b03f76..109f54d9 100644 --- a/spec/lib/operation_id_spec.rb +++ b/spec/lib/operation_id_spec.rb @@ -9,7 +9,7 @@ specify { expect(subject).to respond_to :build } describe 'build' do - let(:route) { Grape::Router::Route.new(method, '/path', requirements: {}) } + let(:route) { RouteHelper.build(method: method, pattern: '/path', options: { requirements: {} }) } describe 'GET' do let(:method) { 'GET' } diff --git a/spec/support/route_helper.rb b/spec/support/route_helper.rb new file mode 100644 index 00000000..6e87ccb5 --- /dev/null +++ b/spec/support/route_helper.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module RouteHelper + def self.build(method:, pattern:, options:, origin: nil) + if GrapeVersion.satisfy?('>= 2.3.0') + Grape::Router::Route.new(method, origin || pattern, pattern, options) + else + Grape::Router::Route.new(method, pattern, **options) + end + end +end