From f7d81cb236e28ba9bf74a03dd5b87eaebf5dac9f Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Tue, 18 Feb 2025 16:46:52 +0100 Subject: [PATCH 1/3] Add spec route helper to complain with Grape >= 2.3.0 --- spec/lib/move_params_spec.rb | 4 ++-- spec/lib/operation_id_spec.rb | 2 +- spec/support/route_helper.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 spec/support/route_helper.rb diff --git a/spec/lib/move_params_spec.rb b/spec/lib/move_params_spec.rb index bd294e453..f0528ac52 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 42b03f761..109f54d96 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 000000000..6e87ccb5e --- /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 From ec6a477f31080003bf7d94e49baf1ed6db634e28 Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Tue, 18 Feb 2025 16:47:27 +0100 Subject: [PATCH 2/3] Explicitly add ostruct gem in case of Ruby 3.5 --- Gemfile | 3 +++ lib/grape-swagger/endpoint.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c5ddc5973..ebfe7cf5a 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 15509be5d..1c4274f00 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 From 5c9561ec101eed7f8bc6b3ce81d41fa4224f471c Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Tue, 18 Feb 2025 17:09:52 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c54b36a59..1d7bc202e 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)