Skip to content

Commit 619e296

Browse files
committed
Grape 2.0.2 compatibility
Running on grape 2.0.2 resulted in the following exceptions: NameError: uninitialized constant Grape::ContentTypes::CONTENT_TYPES # ./lib/grape-swagger/endpoint.rb:15:in `content_types_for' NoMethodError: undefined method `formatters' for module Grape::Formatter # ./lib/grape-swagger/endpoint.rb:14:in `content_types_for' This is due to internal refactorings in grape as of v2.0.2, specifically ruby-grape/grape@fb67ea99 Fixes ruby-grape#939
1 parent a5e2575 commit 619e296

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

grape-swagger.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
1515
s.metadata['rubygems_mfa_required'] = 'true'
1616

1717
s.required_ruby_version = '>= 3.0'
18-
s.add_runtime_dependency 'grape', '>= 1.7', '< 3.0'
18+
s.add_runtime_dependency 'grape', '>= 2.2.0', '< 3.0'
1919
s.add_runtime_dependency 'rack-test', '~> 2'
2020

2121
s.files = Dir['lib/**/*', '*.md', 'LICENSE.txt', 'grape-swagger.gemspec']

lib/grape-swagger/doc_methods/produces_consumes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class << self
77
def call(*args)
88
return ['application/json'] unless args.flatten.present?
99

10-
args.flatten.map { |x| Grape::ContentTypes::CONTENT_TYPES[x] || x }.uniq
10+
args.flatten.map { |x| Grape::ContentTypes::DEFAULTS[x] || x }.uniq
1111
end
1212
end
1313
end

lib/grape-swagger/endpoint.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def content_types_for(target_class)
1111

1212
if content_types.empty?
1313
formats = [target_class.format, target_class.default_format].compact.uniq
14-
formats = Grape::Formatter.formatters(**{}).keys if formats.empty?
15-
content_types = Grape::ContentTypes::CONTENT_TYPES.select do |content_type, _mime_type|
14+
formats = Grape::Formatter::DEFAULTS.keys if formats.empty?
15+
content_types = Grape::ContentTypes::DEFAULTS.select do |content_type, _mime_type|
1616
formats.include? content_type
1717
end.values
1818
end

0 commit comments

Comments
 (0)