Skip to content

Commit 4559093

Browse files
authored
Uses ruby 2.7 (#768)
* Prepare next release - bump version - updates travis matrix to newest ruby versions - removes deprecation warnings of swagger-entity and -representable * Uses Ruby 2.7 - adepts specs - changes method signature - fixes grape version to 1.2.5 -> will be the last release to support it - adds CHANGELOG entry
1 parent 61e62d7 commit 4559093

19 files changed

+120
-151
lines changed

.rubocop.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ AllCops:
44
Exclude:
55
- vendor/**/*
66
- example/**/*
7-
TargetRubyVersion: 2.6
7+
TargetRubyVersion: 2.7
88

99
Layout/EmptyLinesAroundArguments:
1010
Enabled: false
1111

12-
Layout/IndentFirstHashElement:
12+
Layout/FirstHashElementIndentation:
1313
EnforcedStyle: consistent
1414

15+
Layout/LineLength:
16+
Max: 120
17+
Exclude:
18+
- spec/**/*
19+
1520
Metrics/BlockLength:
1621
Exclude:
1722
- spec/**/*
1823

1924
Metrics/ClassLength:
2025
Max: 300
2126

22-
Metrics/LineLength:
23-
Max: 120
24-
Exclude:
25-
- spec/**/*
26-
2727
Metrics/MethodLength:
2828
Exclude:
2929
- spec/**/*

.rubocop_todo.yml

-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ Gemspec/RequiredRubyVersion:
1313
Exclude:
1414
- 'grape-swagger.gemspec'
1515

16-
# Offense count: 1
17-
# Cop supports --auto-correct.
18-
Lint/UnneededCopEnableDirective:
19-
Exclude:
20-
- 'spec/lib/optional_object_spec.rb'
21-
2216
# Offense count: 30
2317
Metrics/AbcSize:
2418
Max: 59

.travis.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ after_success:
77
- bundle exec danger
88

99
rvm:
10-
- 2.4.6
11-
- 2.5.5
12-
- 2.6.3
10+
- 2.5.7
11+
- 2.6.5
12+
- 2.7.0
1313
env:
14-
- MODEL_PARSER=grape-swagger-entity
15-
- MODEL_PARSER=grape-swagger-representable
14+
- GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-entity
15+
- GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-representable
1616
- GRAPE_VERSION=1.0.3
17-
- GRAPE_VERSION=1.2.4
18-
- GRAPE_VERSION=HEAD
17+
- GRAPE_VERSION=1.2.5
1918

2019
matrix:
2120
fast_finish: true
2221

2322
include:
24-
- rvm: 2.3.8
23+
- rvm: 2.4.9
2524
env:
2625
- rvm: ruby-head
2726
env:
2827
- rvm: jruby-head
2928
env:
3029

3130
allow_failures:
32-
- rvm: 2.3.8
31+
- rvm: 2.4.9
3332
- rvm: ruby-head
3433
- rvm: jruby-head

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#### Features
44

55
* Your contribution here.
6+
* [#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).
67
* [#761](https://github.com/ruby-grape/grape-swagger/pull/761): Add an option to configure root element for responses - [@bikolya](https://github.com/bikolya).
8+
* [#749](https://github.com/ruby-grape/grape-swagger/pull/749) Drop support for Ruby 2.3 and below - [@LeFnord](https://github.com/LeFnord).
9+
710

811
#### Fixes
912

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ group :development, :test do
2525
gem 'rack-test'
2626
gem 'rake'
2727
gem 'rdoc'
28-
gem 'rspec', '~> 3.8'
29-
gem 'rubocop', '~> 0.71', require: false
28+
gem 'rspec', '~> 3.9'
29+
gem 'rubocop', '~> 0.75', require: false
3030
end
3131

3232
group :test do

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ Also added support for [representable](https://github.com/apotonick/representabl
104104

105105
```ruby
106106
# For Grape::Entity ( https://github.com/ruby-grape/grape-entity )
107-
gem 'grape-swagger-entity'
107+
gem 'grape-swagger-entity', '~> 0.3'
108108
# For representable ( https://github.com/apotonick/representable )
109-
gem 'grape-swagger-representable'
109+
gem 'grape-swagger-representable', '~> 0.2'
110110
```
111111

112112
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'`.

grape-swagger.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414
s.license = 'MIT'
1515

1616
s.required_ruby_version = '>= 2.4'
17-
s.add_runtime_dependency 'grape', '>= 0.16.2'
17+
s.add_runtime_dependency 'grape', '>= 0.16.2', '<= 1.2.5'
1818

1919
s.files = `git ls-files`.split("\n")
2020
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")

lib/grape-swagger/doc_methods/build_model_definition.rb

-17
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,10 @@ def required_attributes(model)
2525

2626
def parse_entity(model)
2727
return unless model.respond_to?(:documentation)
28-
29-
deprecated_workflow_for('grape-swagger-entity')
30-
31-
model.documentation
32-
.select { |_name, options| options[:required] }
33-
.map { |name, options| options[:as] || name }
3428
end
3529

3630
def parse_representable(model)
3731
return unless model.respond_to?(:map)
38-
39-
deprecated_workflow_for('grape-swagger-representable')
40-
41-
model.map
42-
.select { |p| p[:documentation] && p[:documentation][:required] }
43-
.map(&:name)
44-
end
45-
46-
def deprecated_workflow_for(gem_name)
47-
warn "DEPRECATED: You are using old #{gem_name} version, which doesn't provide " \
48-
"required attributes. To solve this problem, please update #{gem_name}"
4932
end
5033
end
5134
end

lib/grape-swagger/doc_methods/move_params.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MoveParams
88
class << self
99
attr_accessor :definitions
1010

11-
def can_be_moved?(params, http_verb)
11+
def can_be_moved?(http_verb, params)
1212
move_methods.include?(http_verb) && includes_body_param?(params)
1313
end
1414

lib/grape-swagger/endpoint.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def params_object(route, options, path)
186186
GrapeSwagger::DocMethods::ParseParams.call(param, value, path, route, @definitions)
187187
end
188188

189-
if GrapeSwagger::DocMethods::MoveParams.can_be_moved?(parameters, route.request_method)
189+
if GrapeSwagger::DocMethods::MoveParams.can_be_moved?(route.request_method, parameters)
190190
parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(path, parameters, route, @definitions)
191191
end
192192

spec/lib/move_params_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@
4040
describe 'movable params' do
4141
specify 'allowed verbs' do
4242
allowed_verbs.each do |verb|
43-
expect(subject.can_be_moved?(movable_params, verb)).to be true
43+
expect(subject.can_be_moved?(verb, movable_params)).to be true
4444
end
4545
end
4646

4747
specify 'not allowed verbs' do
4848
not_allowed_verbs.each do |verb|
49-
expect(subject.can_be_moved?(movable_params, verb)).to be false
49+
expect(subject.can_be_moved?(verb, movable_params)).to be false
5050
end
5151
end
5252
end
5353

5454
describe 'not movable params' do
5555
specify 'allowed verbs' do
5656
allowed_verbs.each do |verb|
57-
expect(subject.can_be_moved?(not_movable_params, verb)).to be false
57+
expect(subject.can_be_moved?(verb, not_movable_params)).to be false
5858
end
5959
end
6060

6161
specify 'not allowed verbs' do
6262
not_allowed_verbs.each do |verb|
63-
expect(subject.can_be_moved?(not_movable_params, verb)).to be false
63+
expect(subject.can_be_moved?(verb, not_movable_params)).to be false
6464
end
6565
end
6666
end

spec/lib/optional_object_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
let(:options) do
4040
{ host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } }
4141
end
42-
# rubocop:enable RegexpMatch
42+
4343
specify do
4444
expect(subject.build(key, options, request)).to eql '/api-example'
4545
end

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require 'grape'
2020
require 'grape-swagger'
2121

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

spec/swagger_v2/description_not_initialized.rb

-39
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'has no description, if details or description are nil' do
6+
include_context "#{MODEL_PARSER} swagger example"
7+
8+
before :all do
9+
module TheApi
10+
class GfmRcDetailApi < Grape::API
11+
format :json
12+
13+
desc nil,
14+
detail: nil,
15+
entity: Entities::UseResponse,
16+
failure: [{ code: 400, model: Entities::ApiError }]
17+
get '/use_gfm_rc_detail' do
18+
{ 'declared_params' => declared(params) }
19+
end
20+
21+
add_swagger_documentation
22+
end
23+
end
24+
end
25+
26+
def app
27+
TheApi::GfmRcDetailApi
28+
end
29+
30+
subject do
31+
get '/swagger_doc'
32+
JSON.parse(last_response.body)
33+
end
34+
35+
specify do
36+
expect(subject['paths']['/use_gfm_rc_detail']['get']).not_to include('description')
37+
expect(subject['paths']['/use_gfm_rc_detail']['get']['description']).to eql(nil)
38+
end
39+
end

spec/swagger_v2/mounted_target_class_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'docs mounted separately from api' do
5+
xdescribe 'docs mounted separately from api' do
66
before :all do
77
class ActualApi < Grape::API
88
desc 'Document root'

spec/swagger_v2/parent_less_namespace.rb

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'a parent less namespace' do
6+
include_context 'namespace example'
7+
8+
before :all do
9+
class ParentLessApi < Grape::API
10+
prefix :api
11+
mount TheApi::ParentLessNamespaceApi
12+
add_swagger_documentation version: 'v1'
13+
end
14+
end
15+
16+
def app
17+
ParentLessApi
18+
end
19+
20+
describe 'retrieves swagger-documentation on /swagger_doc' do
21+
let(:route_name) { ':animal/:breed/queues/:queue_id/reservations' }
22+
subject do
23+
get '/api/swagger_doc.json'
24+
JSON.parse(last_response.body)
25+
end
26+
27+
specify do
28+
expect(subject['paths']['/api/{animal}/{breed}/queues/{queue_id}/reservations']['get']['operationId'])
29+
.to eql('getApiAnimalBreedQueuesQueueIdReservations')
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)