From 0c10c531a767a4662dd02442297c4af8ac96d837 Mon Sep 17 00:00:00 2001 From: Patrick Oscity Date: Mon, 16 Sep 2024 18:02:16 +0200 Subject: [PATCH 1/5] Run `rubocop -a` --- grape-swagger.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'] From 700987faf1ce6bfca892f7555ce5a313e29b0ad2 Mon Sep 17 00:00:00 2001 From: Patrick Oscity Date: Mon, 16 Sep 2024 18:09:15 +0200 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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. From 012afc99bea3e21b03046f061ec5d5e4f1d077e5 Mon Sep 17 00:00:00 2001 From: Patrick Oscity Date: Tue, 17 Sep 2024 12:24:31 +0200 Subject: [PATCH 3/5] Run CI against grape 2.1.x and 2.2.x --- .github/workflows/ci.yml | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dceb411..5ca24a53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,6 +119,70 @@ jobs: bundle update bundle exec rspec + grape-21: + runs-on: ubuntu-latest + needs: ['rubocop'] + env: + GRAPE_VERSION: '2.1.3' + 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-22: + runs-on: ubuntu-latest + needs: ['rubocop'] + env: + GRAPE_VERSION: '2.2.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'] From a6b31de7fdc4794f8d3ef728d9137100e3b1d927 Mon Sep 17 00:00:00 2001 From: Patrick Oscity Date: Tue, 17 Sep 2024 12:58:08 +0200 Subject: [PATCH 4/5] Copy formatter and content type defaults from grape --- lib/grape-swagger.rb | 18 ++++++++++++++++++ .../doc_methods/produces_consumes.rb | 2 +- lib/grape-swagger/endpoint.rb | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) 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 From e0c8ba889782a9e3b17c9ad140b7216b3d889189 Mon Sep 17 00:00:00 2001 From: Patrick Oscity Date: Thu, 19 Sep 2024 23:25:18 +0200 Subject: [PATCH 5/5] Use matrix to reduce duplication in CI workflow --- .github/workflows/ci.yml | 200 +++++++-------------------------------- 1 file changed, 35 insertions(+), 165 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ca24a53..e68f6dae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,182 +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-21: - runs-on: ubuntu-latest - needs: ['rubocop'] - env: - GRAPE_VERSION: '2.1.3' - 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-22: - runs-on: ubuntu-latest - needs: ['rubocop'] - env: - GRAPE_VERSION: '2.2.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