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:
parent
7f3497eecb
commit
6c5e386a32
|
@ -9,5 +9,9 @@ Metrics/LineLength:
|
|||
Exclude:
|
||||
- spec/**/*
|
||||
|
||||
Metrics/MethodLength:
|
||||
Exclude:
|
||||
- spec/**/*
|
||||
|
||||
Style/IndentHash:
|
||||
EnforcedStyle: consistent
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
# This configuration was generated by
|
||||
# `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
|
||||
# one by one as the offenses are removed from the code base.
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
# versions of RuboCop, may require this file to be generated again.
|
||||
|
||||
# Offense count: 27
|
||||
# Offense count: 29
|
||||
Metrics/AbcSize:
|
||||
Max: 56
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/BlockLength:
|
||||
Max: 30
|
||||
Max: 29
|
||||
|
||||
# Offense count: 3
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/ClassLength:
|
||||
Max: 265
|
||||
|
||||
# Offense count: 10
|
||||
# Offense count: 12
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 15
|
||||
Max: 14
|
||||
|
||||
# Offense count: 803
|
||||
# Offense count: 129
|
||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
||||
# URISchemes: http, https
|
||||
Metrics/LineLength:
|
||||
Max: 120
|
||||
|
||||
# Offense count: 34
|
||||
# Offense count: 35
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/MethodLength:
|
||||
Max: 101
|
||||
Max: 40
|
||||
|
||||
# Offense count: 5
|
||||
# Offense count: 7
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 16
|
||||
Max: 15
|
||||
|
||||
# Offense count: 3
|
||||
Style/ClassVars:
|
||||
|
@ -58,20 +58,13 @@ Style/FileName:
|
|||
- 'spec/swagger_v2/api_swagger_v2_type-format_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
|
||||
# Cop supports --auto-correct.
|
||||
Style/MultilineIfModifier:
|
||||
Exclude:
|
||||
- 'lib/grape-swagger/grape/route.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
||||
# SupportedStyles: slashes, percent_r, mixed
|
||||
|
|
29
.travis.yml
29
.travis.yml
|
@ -6,26 +6,29 @@ before_install:
|
|||
|
||||
matrix:
|
||||
include:
|
||||
- rvm: 2.3.3
|
||||
- rvm: 2.4.0
|
||||
script:
|
||||
- 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
|
||||
env: MODEL_PARSER=grape-swagger-entity
|
||||
- rvm: 2.3.3
|
||||
env: MODEL_PARSER=grape-swagger-representable
|
||||
- rvm: 2.3.3
|
||||
env: GRAPE_VERSION=0.14.0
|
||||
- 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: 2.2.6
|
||||
- rvm: ruby-head
|
||||
- rvm: jruby-9.1.6.0
|
||||
- rvm: jruby-head
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#### 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.
|
||||
|
||||
#### Fixes
|
||||
|
|
6
Gemfile
6
Gemfile
|
@ -4,7 +4,7 @@ ruby RUBY_VERSION
|
|||
|
||||
gemspec
|
||||
|
||||
gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.18'
|
||||
gem 'grape', case version = ENV['GRAPE_VERSION'] || '~> 0.19'
|
||||
when 'HEAD'
|
||||
{ github: 'ruby-grape/grape' }
|
||||
else
|
||||
|
@ -23,7 +23,7 @@ group :development, :test do
|
|||
gem 'rack-test'
|
||||
gem 'rake'
|
||||
gem 'rdoc'
|
||||
gem 'redcarpet', platforms: [:mri]
|
||||
gem 'redcarpet', '< 3.4', platforms: [:mri]
|
||||
gem 'rouge', platforms: [:mri]
|
||||
gem 'rspec', '~> 3.0'
|
||||
gem 'rubocop', '~> 0.40'
|
||||
|
@ -32,5 +32,5 @@ end
|
|||
group :test do
|
||||
gem 'grape-entity'
|
||||
gem 'grape-swagger-entity'
|
||||
gem 'ruby-grape-danger', '~> 0.1.0', require: false
|
||||
gem 'ruby-grape-danger', '~> 0.1.1', require: false
|
||||
end
|
||||
|
|
|
@ -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.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.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" />
|
||||
## Swagger-Spec
|
||||
|
|
2
Rakefile
2
Rakefile
|
@ -17,4 +17,4 @@ RSpec::Core::RakeTask.new(:spec)
|
|||
require 'rubocop/rake_task'
|
||||
RuboCop::RakeTask.new(:rubocop)
|
||||
|
||||
task default: [:rubocop, :spec]
|
||||
task default: [:spec, :rubocop]
|
||||
|
|
|
@ -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.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.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
require 'grape'
|
||||
|
||||
require 'grape-swagger/grape/route'
|
||||
|
||||
require 'grape-swagger/version'
|
||||
require 'grape-swagger/endpoint'
|
||||
require 'grape-swagger/errors'
|
||||
|
|
|
@ -10,6 +10,7 @@ require 'grape-swagger/doc_methods/parse_params'
|
|||
require 'grape-swagger/doc_methods/move_params'
|
||||
require 'grape-swagger/doc_methods/headers'
|
||||
require 'grape-swagger/doc_methods/build_model_definition'
|
||||
require 'grape-swagger/doc_methods/version'
|
||||
|
||||
module GrapeSwagger
|
||||
module DocMethods
|
||||
|
|
|
@ -15,7 +15,9 @@ module GrapeSwagger
|
|||
item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item'
|
||||
|
||||
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
|
||||
path.sub!('/{version}', '')
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -228,9 +228,11 @@ module Grape
|
|||
end
|
||||
|
||||
def tag_object(route)
|
||||
version = GrapeSwagger::DocMethods::Version.get(route)
|
||||
version = [version] unless version.is_a?(Array)
|
||||
Array(
|
||||
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
|
||||
|
|
|
@ -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')
|
|
@ -6,14 +6,34 @@ describe 'namespace tags check while using prefix and version' do
|
|||
before :all do
|
||||
module TheApi
|
||||
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
|
||||
|
||||
class TagApi < Grape::API
|
||||
prefix :api
|
||||
mount TheApi::CascadingVersionApi
|
||||
mount TheApi::NamespaceApi
|
||||
add_swagger_documentation version: 'v1'
|
||||
add_swagger_documentation
|
||||
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/niles/items']['post']['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
|
||||
|
||||
|
|
Loading…
Reference in New Issue