Skip to content

Commit

Permalink
Grape 2.0.2 compatibility
Browse files Browse the repository at this point in the history
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 #939
  • Loading branch information
padde committed Sep 16, 2024
1 parent a5e2575 commit 66f5f93
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#### Fixes

* [#000](https://github.com/ruby-grape/grape-swagger/pull/000): Grape 2.0.2 compatibility - [@padde](https://github.com/padde)
* Your contribution here.


Expand Down
2 changes: 1 addition & 1 deletion grape-swagger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.metadata['rubygems_mfa_required'] = 'true'

s.required_ruby_version = '>= 3.0'
s.add_runtime_dependency 'grape', '>= 1.7', '< 3.0'
s.add_runtime_dependency 'grape', '>= 2.2.0', '< 3.0'
s.add_runtime_dependency 'rack-test', '~> 2'

s.files = Dir['lib/**/*', '*.md', 'LICENSE.txt', 'grape-swagger.gemspec']
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/produces_consumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class << self
def call(*args)
return ['application/json'] unless args.flatten.present?

args.flatten.map { |x| Grape::ContentTypes::CONTENT_TYPES[x] || x }.uniq
args.flatten.map { |x| Grape::ContentTypes::DEFAULTS[x] || x }.uniq
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def content_types_for(target_class)

if content_types.empty?
formats = [target_class.format, target_class.default_format].compact.uniq
formats = Grape::Formatter.formatters(**{}).keys if formats.empty?
content_types = Grape::ContentTypes::CONTENT_TYPES.select do |content_type, _mime_type|
formats = Grape::Formatter::DEFAULTS.keys if formats.empty?
content_types = Grape::ContentTypes::DEFAULTS.select do |content_type, _mime_type|
formats.include? content_type
end.values
end
Expand Down

0 comments on commit 66f5f93

Please sign in to comment.