Skip to content

Adds ruby 3.0 support. #818

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

Merged
merged 1 commit into from
Feb 16, 2021
Merged
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
32 changes: 32 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Ruby

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
rspec:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0']
grape-version: [1.5.2, 1.4.0, 1.3.3]
model-parser: [grape-swagger-entity, grape-swagger-representable]

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
with:
ruby-version: ${{ matrix.ruby-version }}
GRAPE_VERSION: ${{ matrix.grape-version }}
MODEL_PARSER: ${{ matrix.model-parser }}
bundler-cache: true
- name: Run rspec
run: bundle exec rspec
- name: Run rubocop
run: bundle exec rubocop
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ AllCops:
- vendor/**/*
- example/**/*
NewCops: enable
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
SuggestExtensions: false

# Layout stuff
#
Expand Down
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion grape-swagger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
s.license = 'MIT'

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

s.files = `git ls-files`.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def build_root(route, reference, response_model, settings)
end

def file_response?(value)
value.to_s.casecmp('file').zero? ? true : false
value.to_s.casecmp('file').zero?
end

def build_file_response(memo)
Expand Down
4 changes: 2 additions & 2 deletions lib/grape-swagger/model_parsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def insert_before(before_klass, klass, ancestor)
subhash = @parsers.except(klass).to_a
insert_at = subhash.index(subhash.assoc(before_klass))
insert_at = subhash.length - 1 if insert_at.nil?
@parsers = Hash[subhash.insert(insert_at, [klass, ancestor])]
@parsers = subhash.insert(insert_at, [klass, ancestor]).to_h
end

def insert_after(after_klass, klass, ancestor)
subhash = @parsers.except(klass).to_a
insert_at = subhash.index(subhash.assoc(after_klass))
insert_at = subhash.length - 1 if insert_at.nil?
@parsers = Hash[subhash.insert(insert_at + 1, [klass, ancestor])]
@parsers = subhash.insert(insert_at + 1, [klass, ancestor]).to_h
end

def each
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require 'grape'
require 'grape-swagger'

Dir[File.join(Dir.getwd, 'spec/support/*.rb')].sort.each { |f| require f }
Dir[File.join(Dir.getwd, 'spec/support/*.rb')].each { |f| require f }
require "grape-swagger/#{MODEL_PARSER}" if MODEL_PARSER != 'mock'
require File.join(Dir.getwd, "spec/support/model_parsers/#{MODEL_PARSER}_parser.rb")

Expand Down
6 changes: 4 additions & 2 deletions spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class ResponseApiHeaders < Grape::API
end

desc 'A 204 can have headers too' do
success Hash[status: 204, message: 'No content', headers: { 'Location' => { description: 'Location of resource', type: 'string' } }]
foo = { status: 204, message: 'No content', headers: { 'Location' => { description: 'Location of resource', type: 'string' } } }
success foo
failure [[400, 'Bad Request', Entities::ApiError, { 'application/json' => { code: 400, message: 'Bad request' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
end
delete '/no_content_response_headers' do
{ 'declared_params' => declared(params) }
end

desc 'A file can have headers too' do
success Hash[status: 200, model: 'File', headers: { 'Cache-Control' => { description: 'Directive for caching', type: 'string' } }]
foo = { status: 200, model: 'File', headers: { 'Cache-Control': { description: 'Directive for caching', type: 'string' } } }
success foo
failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
end
get '/file_response_headers' do
Expand Down