diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dceb411..e68f6dae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,118 +22,52 @@ jobs: bundler-cache: true - name: Run rubocop run: bundle exec rubocop --parallel --format progress - - grape-17: - runs-on: ubuntu-latest - needs: ['rubocop'] - env: - GRAPE_VERSION: '1.7.1' + test: 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-18: + 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 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'] + GRAPE_VERSION: ${{ matrix.entry.grape }} steps: - name: Check out branch uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby-version }} + ruby-version: ${{ matrix.entry.ruby }} - name: Run rspec wo model parser run: | bundle update diff --git a/CHANGELOG.md b/CHANGELOG.md index 695c0929..e5b3a773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ #### Fixes +* [#940](https://github.com/ruby-grape/grape-swagger/pull/940): Grape 2.2.0 compatibility - [@padde](https://github.com/padde) * Your contribution here. diff --git a/grape-swagger.gemspec b/grape-swagger.gemspec index 80377959..cd6c693f 100644 --- a/grape-swagger.gemspec +++ b/grape-swagger.gemspec @@ -15,8 +15,8 @@ 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 'rack-test', '~> 2' + s.add_dependency 'grape', '>= 1.7', '< 3.0' + s.add_dependency 'rack-test', '~> 2' s.files = Dir['lib/**/*', '*.md', 'LICENSE.txt', 'grape-swagger.gemspec'] s.require_paths = ['lib'] diff --git a/lib/grape-swagger.rb b/lib/grape-swagger.rb index 76474a19..7a36ea0c 100644 --- a/lib/grape-swagger.rb +++ b/lib/grape-swagger.rb @@ -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 diff --git a/lib/grape-swagger/doc_methods/produces_consumes.rb b/lib/grape-swagger/doc_methods/produces_consumes.rb index 3359e4b6..5fae277e 100644 --- a/lib/grape-swagger/doc_methods/produces_consumes.rb +++ b/lib/grape-swagger/doc_methods/produces_consumes.rb @@ -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 diff --git a/lib/grape-swagger/endpoint.rb b/lib/grape-swagger/endpoint.rb index dd93f864..a3f4f108 100644 --- a/lib/grape-swagger/endpoint.rb +++ b/lib/grape-swagger/endpoint.rb @@ -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