Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TI-427: Add compatibility with Grape 2.2 #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ def model_parsers
end
end
autoload :Rake, 'grape-swagger/rake/oapi_tasks'

# Copied from https://github.com/ruby-grape/grape/blob/v2.2.0/lib/grape/formatter.rb
FORMATTER_DEFAULTS = {
json: Grape::Formatter::Json,
jsonapi: Grape::Formatter::Json,
serializable_hash: Grape::Formatter::SerializableHash,
txt: Grape::Formatter::Txt,
xml: Grape::Formatter::Xml
}.freeze

# Copied from https://github.com/ruby-grape/grape/blob/v2.2.0/lib/grape/content_types.rb
CONTENT_TYPE_DEFAULTS = {
xml: 'application/xml',
serializable_hash: 'application/json',
json: 'application/json',
binary: 'application/octet-stream',
txt: 'text/plain'
}.freeze
end

module SwaggerRouting
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| GrapeSwagger::CONTENT_TYPE_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 = GrapeSwagger::FORMATTER_DEFAULTS.keys if formats.empty?
content_types = GrapeSwagger::CONTENT_TYPE_DEFAULTS.select do |content_type, _mime_type|
formats.include? content_type
end.values
end
Expand Down
2 changes: 1 addition & 1 deletion tastyworks-grape_swagger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.metadata['github_repo'] = 'ssh://github.com/tastyworks/grape-swagger'

s.required_ruby_version = '>= 2.5'
s.add_runtime_dependency 'grape', '~> 1.3'
s.add_runtime_dependency 'grape', '>= 1.3', '< 3.0'

s.files = `git ls-files`.split("\n")
s.require_paths = ['lib']
Expand Down