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
This commit is contained in:
peter scholz 2016-12-27 12:27:24 +01:00 committed by LeFnord
parent 7f3497eecb
commit 6c5e386a32
15 changed files with 92 additions and 59 deletions

View File

@ -9,5 +9,9 @@ Metrics/LineLength:
Exclude: Exclude:
- spec/**/* - spec/**/*
Metrics/MethodLength:
Exclude:
- spec/**/*
Style/IndentHash: Style/IndentHash:
EnforcedStyle: consistent EnforcedStyle: consistent

View File

@ -1,43 +1,43 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2016-10-31 11:51:42 +0100 using RuboCop version 0.45.0. # on 2016-11-24 18:42:08 +0800 using RuboCop version 0.45.0.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again. # versions of RuboCop, may require this file to be generated again.
# Offense count: 27 # Offense count: 29
Metrics/AbcSize: Metrics/AbcSize:
Max: 56 Max: 56
# Offense count: 1 # Offense count: 1
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/BlockLength: Metrics/BlockLength:
Max: 30 Max: 29
# Offense count: 3 # Offense count: 3
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
Max: 265 Max: 265
# Offense count: 10 # Offense count: 12
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 15 Max: 14
# Offense count: 803 # Offense count: 129
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives. # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# URISchemes: http, https # URISchemes: http, https
Metrics/LineLength: Metrics/LineLength:
Max: 120 Max: 120
# Offense count: 34 # Offense count: 35
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/MethodLength: Metrics/MethodLength:
Max: 101 Max: 40
# Offense count: 5 # Offense count: 7
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 16 Max: 15
# Offense count: 3 # Offense count: 3
Style/ClassVars: Style/ClassVars:
@ -58,20 +58,13 @@ Style/FileName:
- 'spec/swagger_v2/api_swagger_v2_type-format_spec.rb' - 'spec/swagger_v2/api_swagger_v2_type-format_spec.rb'
- 'spec/swagger_v2/grape-swagger_spec.rb' - 'spec/swagger_v2/grape-swagger_spec.rb'
# Offense count: 94
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: when_needed, always
Style/FrozenStringLiteralComment:
Enabled: false
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/MultilineIfModifier: Style/MultilineIfModifier:
Exclude: Exclude:
- 'lib/grape-swagger/grape/route.rb' - 'lib/grape-swagger/grape/route.rb'
# Offense count: 4 # Offense count: 5
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed # SupportedStyles: slashes, percent_r, mixed

View File

@ -6,26 +6,29 @@ before_install:
matrix: matrix:
include: include:
- rvm: 2.3.3 - rvm: 2.4.0
script: script:
- bundle exec danger - bundle exec danger
- rvm: 2.4.0
env: MODEL_PARSER=grape-swagger-entity
- rvm: 2.4.0
env: MODEL_PARSER=grape-swagger-representable
- rvm: 2.4.0
env: GRAPE_VERSION=0.16.2
- rvm: 2.4.0
env: GRAPE_VERSION=0.17.0
- rvm: 2.4.0
env: GRAPE_VERSION=0.18.0
- rvm: 2.4.0
env: GRAPE_VERSION=0.19.0
- rvm: 2.4.0
env: GRAPE_VERSION=HEAD
- rvm: 2.3.3 - rvm: 2.3.3
env: MODEL_PARSER=grape-swagger-entity env: MODEL_PARSER=grape-swagger-entity
- rvm: 2.3.3 - rvm: 2.3.3
env: MODEL_PARSER=grape-swagger-representable env: MODEL_PARSER=grape-swagger-representable
- rvm: 2.3.3 - rvm: 2.3.3
env: GRAPE_VERSION=0.14.0 - rvm: 2.2.6
- rvm: 2.3.3
env: GRAPE_VERSION=0.15.0
- rvm: 2.3.3
env: GRAPE_VERSION=0.16.2
- rvm: 2.3.3
env: GRAPE_VERSION=0.17.0
- rvm: 2.3.3
env: GRAPE_VERSION=0.18.0
- rvm: 2.3.3
env: GRAPE_VERSION=HEAD
- rvm: 2.2
- rvm: ruby-head - rvm: ruby-head
- rvm: jruby-9.1.6.0 - rvm: jruby-9.1.6.0
- rvm: jruby-head - rvm: jruby-head

View File

@ -2,6 +2,9 @@
#### Features #### Features
* [#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).
* [#535](https://github.com/ruby-grape/grape-swagger/pull/535): Add support for grape version cascading - [@qinix](https://github.com/qinix).
* Your contribution here. * Your contribution here.
#### Fixes #### Fixes

View File

@ -4,7 +4,7 @@ ruby RUBY_VERSION
gemspec gemspec
gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.18' gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.19'
when 'HEAD' when 'HEAD'
{ github: 'ruby-grape/grape' } { github: 'ruby-grape/grape' }
else else
@ -23,7 +23,7 @@ group :development, :test do
gem 'rack-test' gem 'rack-test'
gem 'rake' gem 'rake'
gem 'rdoc' gem 'rdoc'
gem 'redcarpet', platforms: [:mri] gem 'redcarpet', '< 3.4', platforms: [:mri]
gem 'rouge', platforms: [:mri] gem 'rouge', platforms: [:mri]
gem 'rspec', '~> 3.0' gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.40' gem 'rubocop', '~> 0.40'
@ -32,5 +32,5 @@ end
group :test do group :test do
gem 'grape-entity' gem 'grape-entity'
gem 'grape-swagger-entity' gem 'grape-swagger-entity'
gem 'ruby-grape-danger', '~> 0.1.0', require: false gem 'ruby-grape-danger', '~> 0.1.1', require: false
end end

View File

@ -54,6 +54,8 @@ grape-swagger | swagger spec | grape | grape-entity | represen
0.23.0 | 2.0 | >= 0.12.0 ... <= 0.17.0 | <= 0.5.1 | >= 2.4.1 | 0.23.0 | 2.0 | >= 0.12.0 ... <= 0.17.0 | <= 0.5.1 | >= 2.4.1 |
0.24.0 | 2.0 | >= 0.12.0 ... <= 0.18.0 | <= 0.5.1 | >= 2.4.1 | 0.24.0 | 2.0 | >= 0.12.0 ... <= 0.18.0 | <= 0.5.1 | >= 2.4.1 |
0.25.0 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.5.2 | >= 2.4.1 | 0.25.0 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.5.2 | >= 2.4.1 |
0.25.2 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.6.0 | >= 2.4.1 |
> 0.25.2 | 2.0 | >= 0.16.2 | <= 0.6.0 | >= 2.4.1 |
<a name="swagger-spec" /> <a name="swagger-spec" />
## Swagger-Spec ## Swagger-Spec

View File

@ -17,4 +17,4 @@ RSpec::Core::RakeTask.new(:spec)
require 'rubocop/rake_task' require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) RuboCop::RakeTask.new(:rubocop)
task default: [:rubocop, :spec] task default: [:spec, :rubocop]

View File

@ -11,7 +11,8 @@ Gem::Specification.new do |s|
s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.' s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
s.license = 'MIT' s.license = 'MIT'
s.add_runtime_dependency 'grape', '>= 0.12.0' s.required_ruby_version = '>= 2.2.6'
s.add_runtime_dependency 'grape', '>= 0.16.2'
s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec}/*`.split("\n") s.test_files = `git ls-files -- {test,spec}/*`.split("\n")

View File

@ -1,7 +1,5 @@
require 'grape' require 'grape'
require 'grape-swagger/grape/route'
require 'grape-swagger/version' require 'grape-swagger/version'
require 'grape-swagger/endpoint' require 'grape-swagger/endpoint'
require 'grape-swagger/errors' require 'grape-swagger/errors'

View File

@ -10,6 +10,7 @@ require 'grape-swagger/doc_methods/parse_params'
require 'grape-swagger/doc_methods/move_params' require 'grape-swagger/doc_methods/move_params'
require 'grape-swagger/doc_methods/headers' require 'grape-swagger/doc_methods/headers'
require 'grape-swagger/doc_methods/build_model_definition' require 'grape-swagger/doc_methods/build_model_definition'
require 'grape-swagger/doc_methods/version'
module GrapeSwagger module GrapeSwagger
module DocMethods module DocMethods

View File

@ -15,7 +15,9 @@ module GrapeSwagger
item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item' item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item'
if route.version && options[:add_version] if route.version && options[:add_version]
path.sub!('{version}', route.version.to_s) version = GrapeSwagger::DocMethods::Version.get(route)
version = version.first while version.is_a?(Array)
path.sub!('{version}', version.to_s)
else else
path.sub!('/{version}', '') path.sub!('/{version}', '')
end end

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
module GrapeSwagger
module DocMethods
class Version
class << self
def get(route)
version = route.version
# for grape version 0.16.2, the version can be a string like '[:v1, :v2]'
# for grape version bigger than 0.16.2, the version can be a array like [:v1, :v2]
if version.is_a?(String) && version.start_with?('[') && version.end_with?(']')
instance_eval(version)
else
version
end
end
end
end
end
end

View File

@ -228,9 +228,11 @@ module Grape
end end
def tag_object(route) def tag_object(route)
version = GrapeSwagger::DocMethods::Version.get(route)
version = [version] unless version.is_a?(Array)
Array( Array(
route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i| route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
i == route.prefix.to_s || i == route.version i == route.prefix.to_s || version.map(&:to_s).include?(i)
end.first end.first
) )
end end

View File

@ -1,17 +0,0 @@
# backwards compatibility for Grape < 0.16.0
module Grape
class Route
[:path, :prefix, :entity, :description, :settings, :params, :headers, :http_codes, :version]
.each do |m|
define_method m do
send "route_#{m}"
end
end
def request_method
route_method
end
attr_reader :options
end
end if defined?(Grape::VERSION) && Gem::Version.new(::Grape::VERSION) < Gem::Version.new('0.16.0')

View File

@ -6,14 +6,34 @@ describe 'namespace tags check while using prefix and version' do
before :all do before :all do
module TheApi module TheApi
class NamespaceApi < Grape::API class NamespaceApi < Grape::API
version :v1 version [:v1, :v2]
end
class CascadingVersionApi < Grape::API
version :v2
namespace :hudson do
desc 'Document root'
get '/' do
end
end
namespace :colorado do
desc 'This gets something.',
notes: '_test_'
get '/simple' do
{ bla: 'something' }
end
end
end end
end end
class TagApi < Grape::API class TagApi < Grape::API
prefix :api prefix :api
mount TheApi::CascadingVersionApi
mount TheApi::NamespaceApi mount TheApi::NamespaceApi
add_swagger_documentation version: 'v1' add_swagger_documentation
end end
end end
@ -43,6 +63,8 @@ describe 'namespace tags check while using prefix and version' do
expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames']) expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
expect(subject['paths']['/api/v1/niles/items']['post']['tags']).to eql(['niles']) expect(subject['paths']['/api/v1/niles/items']['post']['tags']).to eql(['niles'])
expect(subject['paths']['/api/v1/niles/custom']['get']['tags']).to eql(['niles']) expect(subject['paths']['/api/v1/niles/custom']['get']['tags']).to eql(['niles'])
expect(subject['paths']['/api/v2/hudson']['get']['tags']).to eql(['hudson'])
expect(subject['paths']['/api/v2/colorado/simple']['get']['tags']).to eql(['colorado'])
end end
end end