Skip to content

Commit 6c5e386

Browse files
peter scholzLeFnord
peter scholz
authored andcommitted
Version Cascading including dependency updates (#558)
* Grape version cascading (#27) - Add support for grape version cascading - make rubocop happy, fix test - fix test failure for grape lower than 0.17 - refactors getting version from route * updates dependencies - drops grape <0.16.2 support, including code only for grape <0.16.2 - adds ruby 2.4.0 support - adds grape 0.19.0 support - adds changelog entry - updates version matrix - adapts rubocop todo
1 parent 7f3497e commit 6c5e386

15 files changed

+91
-58
lines changed

.rubocop.yml

+4
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ Metrics/LineLength:
99
Exclude:
1010
- spec/**/*
1111

12+
Metrics/MethodLength:
13+
Exclude:
14+
- spec/**/*
15+
1216
Style/IndentHash:
1317
EnforcedStyle: consistent

.rubocop_todo.yml

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-10-31 11:51:42 +0100 using RuboCop version 0.45.0.
3+
# on 2016-11-24 18:42:08 +0800 using RuboCop version 0.45.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 27
9+
# Offense count: 29
1010
Metrics/AbcSize:
1111
Max: 56
1212

1313
# Offense count: 1
1414
# Configuration parameters: CountComments.
1515
Metrics/BlockLength:
16-
Max: 30
16+
Max: 29
1717

1818
# Offense count: 3
1919
# Configuration parameters: CountComments.
2020
Metrics/ClassLength:
2121
Max: 265
2222

23-
# Offense count: 10
23+
# Offense count: 12
2424
Metrics/CyclomaticComplexity:
25-
Max: 15
25+
Max: 14
2626

27-
# Offense count: 803
27+
# Offense count: 129
2828
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
2929
# URISchemes: http, https
3030
Metrics/LineLength:
3131
Max: 120
3232

33-
# Offense count: 34
33+
# Offense count: 35
3434
# Configuration parameters: CountComments.
3535
Metrics/MethodLength:
36-
Max: 101
36+
Max: 40
3737

38-
# Offense count: 5
38+
# Offense count: 7
3939
Metrics/PerceivedComplexity:
40-
Max: 16
40+
Max: 15
4141

4242
# Offense count: 3
4343
Style/ClassVars:
@@ -58,20 +58,13 @@ Style/FileName:
5858
- 'spec/swagger_v2/api_swagger_v2_type-format_spec.rb'
5959
- 'spec/swagger_v2/grape-swagger_spec.rb'
6060

61-
# Offense count: 94
62-
# Cop supports --auto-correct.
63-
# Configuration parameters: EnforcedStyle, SupportedStyles.
64-
# SupportedStyles: when_needed, always
65-
Style/FrozenStringLiteralComment:
66-
Enabled: false
67-
6861
# Offense count: 1
6962
# Cop supports --auto-correct.
7063
Style/MultilineIfModifier:
7164
Exclude:
7265
- 'lib/grape-swagger/grape/route.rb'
7366

74-
# Offense count: 4
67+
# Offense count: 5
7568
# Cop supports --auto-correct.
7669
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
7770
# SupportedStyles: slashes, percent_r, mixed

.travis.yml

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@ before_install:
66

77
matrix:
88
include:
9-
- rvm: 2.3.3
9+
- rvm: 2.4.0
1010
script:
1111
- bundle exec danger
12-
- rvm: 2.3.3
12+
- rvm: 2.4.0
1313
env: MODEL_PARSER=grape-swagger-entity
14-
- rvm: 2.3.3
14+
- rvm: 2.4.0
1515
env: MODEL_PARSER=grape-swagger-representable
16-
- rvm: 2.3.3
17-
env: GRAPE_VERSION=0.14.0
18-
- rvm: 2.3.3
19-
env: GRAPE_VERSION=0.15.0
20-
- rvm: 2.3.3
16+
- rvm: 2.4.0
2117
env: GRAPE_VERSION=0.16.2
22-
- rvm: 2.3.3
18+
- rvm: 2.4.0
2319
env: GRAPE_VERSION=0.17.0
24-
- rvm: 2.3.3
20+
- rvm: 2.4.0
2521
env: GRAPE_VERSION=0.18.0
26-
- rvm: 2.3.3
22+
- rvm: 2.4.0
23+
env: GRAPE_VERSION=0.19.0
24+
- rvm: 2.4.0
2725
env: GRAPE_VERSION=HEAD
28-
- rvm: 2.2
26+
- rvm: 2.3.3
27+
env: MODEL_PARSER=grape-swagger-entity
28+
- rvm: 2.3.3
29+
env: MODEL_PARSER=grape-swagger-representable
30+
- rvm: 2.3.3
31+
- rvm: 2.2.6
2932
- rvm: ruby-head
3033
- rvm: jruby-9.1.6.0
3134
- rvm: jruby-head

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#### Features
44

5+
* [#558](https://github.com/ruby-grape/grape-swagger/pull/558): Version cascading including dependency updates (includes: [LeFnord#27](https://github.com/LeFnord/grape-swagger/pull/27)) - [@LeFnord](https://github.com/LeFnord).
6+
* [#535](https://github.com/ruby-grape/grape-swagger/pull/535): Add support for grape version cascading - [@qinix](https://github.com/qinix).
7+
58
* Your contribution here.
69

710
#### Fixes

Gemfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ruby RUBY_VERSION
44

55
gemspec
66

7-
gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.18'
7+
gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.19'
88
when 'HEAD'
99
{ github: 'ruby-grape/grape' }
1010
else
@@ -23,7 +23,7 @@ group :development, :test do
2323
gem 'rack-test'
2424
gem 'rake'
2525
gem 'rdoc'
26-
gem 'redcarpet', platforms: [:mri]
26+
gem 'redcarpet', '< 3.4', platforms: [:mri]
2727
gem 'rouge', platforms: [:mri]
2828
gem 'rspec', '~> 3.0'
2929
gem 'rubocop', '~> 0.40'
@@ -32,5 +32,5 @@ end
3232
group :test do
3333
gem 'grape-entity'
3434
gem 'grape-swagger-entity'
35-
gem 'ruby-grape-danger', '~> 0.1.0', require: false
35+
gem 'ruby-grape-danger', '~> 0.1.1', require: false
3636
end

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ grape-swagger | swagger spec | grape | grape-entity | represen
5454
0.23.0 | 2.0 | >= 0.12.0 ... <= 0.17.0 | <= 0.5.1 | >= 2.4.1 |
5555
0.24.0 | 2.0 | >= 0.12.0 ... <= 0.18.0 | <= 0.5.1 | >= 2.4.1 |
5656
0.25.0 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.5.2 | >= 2.4.1 |
57+
0.25.2 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.6.0 | >= 2.4.1 |
58+
> 0.25.2 | 2.0 | >= 0.16.2 | <= 0.6.0 | >= 2.4.1 |
5759
5860
<a name="swagger-spec" />
5961
## Swagger-Spec

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ RSpec::Core::RakeTask.new(:spec)
1717
require 'rubocop/rake_task'
1818
RuboCop::RakeTask.new(:rubocop)
1919

20-
task default: [:rubocop, :spec]
20+
task default: [:spec, :rubocop]

grape-swagger.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Gem::Specification.new do |s|
1111
s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
1212
s.license = 'MIT'
1313

14-
s.add_runtime_dependency 'grape', '>= 0.12.0'
14+
s.required_ruby_version = '>= 2.2.6'
15+
s.add_runtime_dependency 'grape', '>= 0.16.2'
1516

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

lib/grape-swagger.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
require 'grape'
22

3-
require 'grape-swagger/grape/route'
4-
53
require 'grape-swagger/version'
64
require 'grape-swagger/endpoint'
75
require 'grape-swagger/errors'

lib/grape-swagger/doc_methods.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require 'grape-swagger/doc_methods/move_params'
1111
require 'grape-swagger/doc_methods/headers'
1212
require 'grape-swagger/doc_methods/build_model_definition'
13+
require 'grape-swagger/doc_methods/version'
1314

1415
module GrapeSwagger
1516
module DocMethods

lib/grape-swagger/doc_methods/path_string.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def build(route, options = {})
1515
item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item'
1616

1717
if route.version && options[:add_version]
18-
path.sub!('{version}', route.version.to_s)
18+
version = GrapeSwagger::DocMethods::Version.get(route)
19+
version = version.first while version.is_a?(Array)
20+
path.sub!('{version}', version.to_s)
1921
else
2022
path.sub!('/{version}', '')
2123
end
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
module GrapeSwagger
3+
module DocMethods
4+
class Version
5+
class << self
6+
def get(route)
7+
version = route.version
8+
# for grape version 0.16.2, the version can be a string like '[:v1, :v2]'
9+
# for grape version bigger than 0.16.2, the version can be a array like [:v1, :v2]
10+
if version.is_a?(String) && version.start_with?('[') && version.end_with?(']')
11+
instance_eval(version)
12+
else
13+
version
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end

lib/grape-swagger/endpoint.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ def apply_success_codes(route)
228228
end
229229

230230
def tag_object(route)
231+
version = GrapeSwagger::DocMethods::Version.get(route)
232+
version = [version] unless version.is_a?(Array)
231233
Array(
232234
route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
233-
i == route.prefix.to_s || i == route.version
235+
i == route.prefix.to_s || version.map(&:to_s).include?(i)
234236
end.first
235237
)
236238
end

lib/grape-swagger/grape/route.rb

-17
This file was deleted.

spec/swagger_v2/namespace_tags_prefix_spec.rb

+24-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,34 @@
66
before :all do
77
module TheApi
88
class NamespaceApi < Grape::API
9-
version :v1
9+
version [:v1, :v2]
10+
end
11+
12+
class CascadingVersionApi < Grape::API
13+
version :v2
14+
15+
namespace :hudson do
16+
desc 'Document root'
17+
get '/' do
18+
end
19+
end
20+
21+
namespace :colorado do
22+
desc 'This gets something.',
23+
notes: '_test_'
24+
25+
get '/simple' do
26+
{ bla: 'something' }
27+
end
28+
end
1029
end
1130
end
1231

1332
class TagApi < Grape::API
1433
prefix :api
34+
mount TheApi::CascadingVersionApi
1535
mount TheApi::NamespaceApi
16-
add_swagger_documentation version: 'v1'
36+
add_swagger_documentation
1737
end
1838
end
1939

@@ -43,6 +63,8 @@ def app
4363
expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
4464
expect(subject['paths']['/api/v1/niles/items']['post']['tags']).to eql(['niles'])
4565
expect(subject['paths']['/api/v1/niles/custom']['get']['tags']).to eql(['niles'])
66+
expect(subject['paths']['/api/v2/hudson']['get']['tags']).to eql(['hudson'])
67+
expect(subject['paths']['/api/v2/colorado/simple']['get']['tags']).to eql(['colorado'])
4668
end
4769
end
4870

0 commit comments

Comments
 (0)