Grape 2.2.0 compatibility (#940)

* Run `rubocop -a`

* Update changelog

* Run CI against grape 2.1.x and 2.2.x

* Copy formatter and content type defaults from grape

* Use matrix to reduce duplication in CI workflow
This commit is contained in:
Patrick Oscity 2024-09-21 11:21:46 +02:00 committed by GitHub
parent a5e2575a02
commit a4190cf2d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 61 additions and 108 deletions

View File

@ -22,118 +22,52 @@ jobs:
bundler-cache: true bundler-cache: true
- name: Run rubocop - name: Run rubocop
run: bundle exec rubocop --parallel --format progress run: bundle exec rubocop --parallel --format progress
test:
grape-17: strategy:
matrix:
entry:
- { ruby: '3.0', grape: '1.7.1' }
- { ruby: '3.1', grape: '1.7.1' }
- { ruby: '3.2', grape: '1.7.1' }
- { ruby: '3.3', grape: '1.7.1' }
- { ruby: 'head', grape: '1.7.1' }
- { ruby: '3.0', grape: '1.8.0' }
- { ruby: '3.1', grape: '1.8.0' }
- { ruby: '3.2', grape: '1.8.0' }
- { ruby: '3.3', grape: '1.8.0' }
- { ruby: 'head', grape: '1.8.0' }
- { ruby: '3.0', grape: '2.0.0' }
- { ruby: '3.1', grape: '2.0.0' }
- { ruby: '3.2', grape: '2.0.0' }
- { ruby: '3.3', grape: '2.0.0' }
- { ruby: 'head', grape: '2.0.0' }
- { ruby: '3.0', grape: '2.1.3' }
- { ruby: '3.1', grape: '2.1.3' }
- { ruby: '3.2', grape: '2.1.3' }
- { ruby: '3.3', grape: '2.1.3' }
- { ruby: 'head', grape: '2.1.3' }
- { ruby: '3.0', grape: '2.2.0' }
- { ruby: '3.1', grape: '2.2.0' }
- { ruby: '3.2', grape: '2.2.0' }
- { ruby: '3.3', grape: '2.2.0' }
- { ruby: 'head', grape: '2.2.0' }
- { ruby: '3.0', grape: 'HEAD' }
- { ruby: '3.1', grape: 'HEAD' }
- { ruby: '3.2', grape: 'HEAD' }
- { ruby: '3.3', grape: 'HEAD' }
- { ruby: 'head', grape: 'HEAD' }
name: test (ruby=${{ matrix.entry.ruby }}, grape=${{ matrix.entry.grape }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: ['rubocop'] needs: ['rubocop']
env: env:
GRAPE_VERSION: '1.7.1' GRAPE_VERSION: ${{ matrix.entry.grape }}
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head']
steps: steps:
- name: Check out branch - name: Check out branch
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
ruby-version: ${{ matrix.ruby-version }} ruby-version: ${{ matrix.entry.ruby }}
- name: Run rspec wo model parser
run: |
bundle update
bundle exec rspec
- name: Run rspec w entity parser
env:
MODEL_PARSER: grape-swagger-entity
run: |
bundle update
bundle exec rspec
- name: Run rspec w representable parser
env:
MODEL_PARSER: grape-swagger-representable
run: |
bundle update
bundle exec rspec
grape-18:
runs-on: ubuntu-latest
needs: ['rubocop']
env:
GRAPE_VERSION: '1.8.0'
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head']
steps:
- name: Check out branch
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Run rspec wo model parser
run: |
bundle update
bundle exec rspec
- name: Run rspec w entity parser
env:
MODEL_PARSER: grape-swagger-entity
run: |
bundle update
bundle exec rspec
- name: Run rspec w representable parser
env:
MODEL_PARSER: grape-swagger-representable
run: |
bundle update
bundle exec rspec
grape-20:
runs-on: ubuntu-latest
needs: ['rubocop']
env:
GRAPE_VERSION: '2.0.0'
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head']
steps:
- name: Check out branch
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Run rspec wo model parser
run: |
bundle update
bundle exec rspec
- name: Run rspec w entity parser
env:
MODEL_PARSER: grape-swagger-entity
run: |
bundle update
bundle exec rspec
- name: Run rspec w representable parser
env:
MODEL_PARSER: grape-swagger-representable
run: |
bundle update
bundle exec rspec
grape-HEAD:
runs-on: ubuntu-latest
needs: ['rubocop']
env:
GRAPE_VERSION: 'HEAD'
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head']
steps:
- name: Check out branch
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Run rspec wo model parser - name: Run rspec wo model parser
run: | run: |
bundle update bundle update

View File

@ -6,6 +6,7 @@
#### Fixes #### Fixes
* [#940](https://github.com/ruby-grape/grape-swagger/pull/940): Grape 2.2.0 compatibility - [@padde](https://github.com/padde)
* Your contribution here. * Your contribution here.

View File

@ -15,8 +15,8 @@ Gem::Specification.new do |s|
s.metadata['rubygems_mfa_required'] = 'true' s.metadata['rubygems_mfa_required'] = 'true'
s.required_ruby_version = '>= 3.0' s.required_ruby_version = '>= 3.0'
s.add_runtime_dependency 'grape', '>= 1.7', '< 3.0' s.add_dependency 'grape', '>= 1.7', '< 3.0'
s.add_runtime_dependency 'rack-test', '~> 2' s.add_dependency 'rack-test', '~> 2'
s.files = Dir['lib/**/*', '*.md', 'LICENSE.txt', 'grape-swagger.gemspec'] s.files = Dir['lib/**/*', '*.md', 'LICENSE.txt', 'grape-swagger.gemspec']
s.require_paths = ['lib'] s.require_paths = ['lib']

View File

@ -18,6 +18,24 @@ module GrapeSwagger
end end
end end
autoload :Rake, 'grape-swagger/rake/oapi_tasks' 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 end
module SwaggerRouting module SwaggerRouting

View File

@ -7,7 +7,7 @@ module GrapeSwagger
def call(*args) def call(*args)
return ['application/json'] unless args.flatten.present? 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 end
end end

View File

@ -11,8 +11,8 @@ module Grape
if content_types.empty? if content_types.empty?
formats = [target_class.format, target_class.default_format].compact.uniq formats = [target_class.format, target_class.default_format].compact.uniq
formats = Grape::Formatter.formatters(**{}).keys if formats.empty? formats = GrapeSwagger::FORMATTER_DEFAULTS.keys if formats.empty?
content_types = Grape::ContentTypes::CONTENT_TYPES.select do |content_type, _mime_type| content_types = GrapeSwagger::CONTENT_TYPE_DEFAULTS.select do |content_type, _mime_type|
formats.include? content_type formats.include? content_type
end.values end.values
end end