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

Uses ruby 2.7 #768

Merged
merged 2 commits into from
Jan 3, 2020
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
14 changes: 7 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ AllCops:
Exclude:
- vendor/**/*
- example/**/*
TargetRubyVersion: 2.6
TargetRubyVersion: 2.7

Layout/EmptyLinesAroundArguments:
Enabled: false

Layout/IndentFirstHashElement:
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/LineLength:
Max: 120
Exclude:
- spec/**/*

Metrics/BlockLength:
Exclude:
- spec/**/*

Metrics/ClassLength:
Max: 300

Metrics/LineLength:
Max: 120
Exclude:
- spec/**/*

Metrics/MethodLength:
Exclude:
- spec/**/*
Expand Down
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ Gemspec/RequiredRubyVersion:
Exclude:
- 'grape-swagger.gemspec'

# Offense count: 1
# Cop supports --auto-correct.
Lint/UnneededCopEnableDirective:
Exclude:
- 'spec/lib/optional_object_spec.rb'

# Offense count: 30
Metrics/AbcSize:
Max: 59
Expand Down
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ after_success:
- bundle exec danger

rvm:
- 2.4.6
- 2.5.5
- 2.6.3
- 2.5.7
- 2.6.5
- 2.7.0
env:
- MODEL_PARSER=grape-swagger-entity
- MODEL_PARSER=grape-swagger-representable
- GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-entity
- GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-representable
- GRAPE_VERSION=1.0.3
- GRAPE_VERSION=1.2.4
- GRAPE_VERSION=HEAD
- GRAPE_VERSION=1.2.5

matrix:
fast_finish: true

include:
- rvm: 2.3.8
- rvm: 2.4.9
env:
- rvm: ruby-head
env:
- rvm: jruby-head
env:

allow_failures:
- rvm: 2.3.8
- rvm: 2.4.9
- rvm: ruby-head
- rvm: jruby-head
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#### Features

* Your contribution here.
* [#768](https://github.com/ruby-grape/grape-swagger/pull/768): Uses ruby 2.7, fixes grape to 1.2.5 (cause of dry-types) - [@LeFnord](https://github.com/LeFnord).
* [#761](https://github.com/ruby-grape/grape-swagger/pull/761): Add an option to configure root element for responses - [@bikolya](https://github.com/bikolya).
* [#749](https://github.com/ruby-grape/grape-swagger/pull/749) Drop support for Ruby 2.3 and below - [@LeFnord](https://github.com/LeFnord).


#### Fixes

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ group :development, :test do
gem 'rack-test'
gem 'rake'
gem 'rdoc'
gem 'rspec', '~> 3.8'
gem 'rubocop', '~> 0.71', require: false
gem 'rspec', '~> 3.9'
gem 'rubocop', '~> 0.75', require: false
end

group :test do
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ Also added support for [representable](https://github.com/apotonick/representabl

```ruby
# For Grape::Entity ( https://github.com/ruby-grape/grape-entity )
gem 'grape-swagger-entity'
gem 'grape-swagger-entity', '~> 0.3'
# For representable ( https://github.com/apotonick/representable )
gem 'grape-swagger-representable'
gem 'grape-swagger-representable', '~> 0.2'
```

If you are not using Rails, make sure to load the parser inside your application initialization logic, e.g., via `require 'grape-swagger/entity'` or `require 'grape-swagger/representable'`.
Expand Down
2 changes: 1 addition & 1 deletion grape-swagger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.license = 'MIT'

s.required_ruby_version = '>= 2.4'
s.add_runtime_dependency 'grape', '>= 0.16.2'
s.add_runtime_dependency 'grape', '>= 0.16.2', '<= 1.2.5'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
Expand Down
17 changes: 0 additions & 17 deletions lib/grape-swagger/doc_methods/build_model_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,10 @@ def required_attributes(model)

def parse_entity(model)
return unless model.respond_to?(:documentation)

deprecated_workflow_for('grape-swagger-entity')

model.documentation
.select { |_name, options| options[:required] }
.map { |name, options| options[:as] || name }
end

def parse_representable(model)
return unless model.respond_to?(:map)

deprecated_workflow_for('grape-swagger-representable')

model.map
.select { |p| p[:documentation] && p[:documentation][:required] }
.map(&:name)
end

def deprecated_workflow_for(gem_name)
warn "DEPRECATED: You are using old #{gem_name} version, which doesn't provide " \
"required attributes. To solve this problem, please update #{gem_name}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/move_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MoveParams
class << self
attr_accessor :definitions

def can_be_moved?(params, http_verb)
def can_be_moved?(http_verb, params)
move_methods.include?(http_verb) && includes_body_param?(params)
end

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 @@ -186,7 +186,7 @@ def params_object(route, options, path)
GrapeSwagger::DocMethods::ParseParams.call(param, value, path, route, @definitions)
end

if GrapeSwagger::DocMethods::MoveParams.can_be_moved?(parameters, route.request_method)
if GrapeSwagger::DocMethods::MoveParams.can_be_moved?(route.request_method, parameters)
parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(path, parameters, route, @definitions)
end

Expand Down
8 changes: 4 additions & 4 deletions spec/lib/move_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@
describe 'movable params' do
specify 'allowed verbs' do
allowed_verbs.each do |verb|
expect(subject.can_be_moved?(movable_params, verb)).to be true
expect(subject.can_be_moved?(verb, movable_params)).to be true
end
end

specify 'not allowed verbs' do
not_allowed_verbs.each do |verb|
expect(subject.can_be_moved?(movable_params, verb)).to be false
expect(subject.can_be_moved?(verb, movable_params)).to be false
end
end
end

describe 'not movable params' do
specify 'allowed verbs' do
allowed_verbs.each do |verb|
expect(subject.can_be_moved?(not_movable_params, verb)).to be false
expect(subject.can_be_moved?(verb, not_movable_params)).to be false
end
end

specify 'not allowed verbs' do
not_allowed_verbs.each do |verb|
expect(subject.can_be_moved?(not_movable_params, verb)).to be false
expect(subject.can_be_moved?(verb, not_movable_params)).to be false
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/optional_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
let(:options) do
{ host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } }
end
# rubocop:enable RegexpMatch

specify do
expect(subject.build(key, options, request)).to eql '/api-example'
end
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')].each { |f| require f }
Dir[File.join(Dir.getwd, 'spec/support/*.rb')].sort.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
39 changes: 0 additions & 39 deletions spec/swagger_v2/description_not_initialized.rb

This file was deleted.

39 changes: 39 additions & 0 deletions spec/swagger_v2/description_not_initialized_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'has no description, if details or description are nil' do
include_context "#{MODEL_PARSER} swagger example"

before :all do
module TheApi
class GfmRcDetailApi < Grape::API
format :json

desc nil,
detail: nil,
entity: Entities::UseResponse,
failure: [{ code: 400, model: Entities::ApiError }]
get '/use_gfm_rc_detail' do
{ 'declared_params' => declared(params) }
end

add_swagger_documentation
end
end
end

def app
TheApi::GfmRcDetailApi
end

subject do
get '/swagger_doc'
JSON.parse(last_response.body)
end

specify do
expect(subject['paths']['/use_gfm_rc_detail']['get']).not_to include('description')
expect(subject['paths']['/use_gfm_rc_detail']['get']['description']).to eql(nil)
end
end
2 changes: 1 addition & 1 deletion spec/swagger_v2/mounted_target_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

describe 'docs mounted separately from api' do
xdescribe 'docs mounted separately from api' do
before :all do
class ActualApi < Grape::API
desc 'Document root'
Expand Down
49 changes: 0 additions & 49 deletions spec/swagger_v2/parent_less_namespace.rb

This file was deleted.

32 changes: 32 additions & 0 deletions spec/swagger_v2/parent_less_namespace_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'a parent less namespace' do
include_context 'namespace example'

before :all do
class ParentLessApi < Grape::API
prefix :api
mount TheApi::ParentLessNamespaceApi
add_swagger_documentation version: 'v1'
end
end

def app
ParentLessApi
end

describe 'retrieves swagger-documentation on /swagger_doc' do
let(:route_name) { ':animal/:breed/queues/:queue_id/reservations' }
subject do
get '/api/swagger_doc.json'
JSON.parse(last_response.body)
end

specify do
expect(subject['paths']['/api/{animal}/{breed}/queues/{queue_id}/reservations']['get']['operationId'])
.to eql('getApiAnimalBreedQueuesQueueIdReservations')
end
end
end
Loading