Skip to content

Commit

Permalink
Merge pull request #409 from dblock/grape-0.15.x
Browse files Browse the repository at this point in the history
Added support for Grape 0.15.x, part of #407.
  • Loading branch information
dblock committed May 6, 2016
2 parents 586b48b + a4bbb7c commit 819fcc5
Show file tree
Hide file tree
Showing 59 changed files with 1,585 additions and 1,533 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
AllCops:
Exclude:
- vendor/**/*
- spec/**/*
- swagger_spec1.2/**/*
- example/**/*

inherit_from: .rubocop_todo.yml
76 changes: 43 additions & 33 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,83 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-08-19 12:17:53 -0400 using RuboCop version 0.33.0.
# on 2016-05-06 15:08:19 -0400 using RuboCop version 0.39.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: 10
Metrics/AbcSize:
Max: 176
# Offense count: 1
Lint/AmbiguousOperator:
Exclude:
- 'spec/lib/move_params_spec.rb'

# Offense count: 1
Lint/UnreachableCode:
Exclude:
- 'example/config.ru'

# Offense count: 1
Lint/UselessAssignment:
Exclude:
- 'spec/lib/move_params_spec.rb'

# Offense count: 27
Metrics/AbcSize:
Max: 68

# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 250
Max: 234

# Offense count: 6
# Offense count: 11
Metrics/CyclomaticComplexity:
Max: 38
Max: 16

# Offense count: 304
# Configuration parameters: AllowURI, URISchemes.
# Offense count: 624
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 242
Max: 487

# Offense count: 21
# Offense count: 33
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 139
Max: 101

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 200

# Offense count: 4
# Offense count: 7
Metrics/PerceivedComplexity:
Max: 38
Max: 19

# Offense count: 8
# Offense count: 4
Style/ClassVars:
Exclude:
- 'example/api.rb'
- 'example/api/endpoints.rb'
- 'lib/grape-swagger/doc_methods.rb'

# Offense count: 90
# Offense count: 24
Style/Documentation:
Enabled: false

# Offense count: 2
# Offense count: 1
Style/DoubleNegation:
Exclude:
- 'example/api/endpoints.rb'

# Offense count: 3
# Configuration parameters: Exclude.
# Offense count: 5
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
Style/FileName:
Exclude:
- 'lib/grape-swagger.rb'
- 'spec/grape-swagger_helper_spec.rb'
- 'spec/grape-swagger_spec.rb'
- 'spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb'
- 'spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb'
- 'spec/swagger_v2/api_swagger_v2_type-format_spec.rb'
- 'spec/swagger_v2/grape-swagger_spec.rb'

# Offense count: 1
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
Style/PredicateName:
Exclude:

# Offense count: 4
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'lib/grape-swagger.rb'
34 changes: 23 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ language: ruby

sudo: false

rvm:
- 2.3.1
- 2.2.5
- jruby-9.0.5.0
- rbx-2

matrix:
include:
- rvm: 2.3.1
env: GRAPE_VERSION=0.12.0
- rvm: 2.3.1
env: GRAPE_VERSION=0.13.0
- rvm: 2.3.1
env: GRAPE_VERSION=0.14.0
- rvm: 2.3.1
env: GRAPE_VERSION=0.15.0
# - rvm: 2.3.1
# env: GRAPE_VERSION=0.16.0
# - rvm: 2.3.1
# env: GRAPE_VERSION=HEAD
- rvm: 2.3.0
- rvm: 2.2.5
- rvm: 2.1
- rvm: rbx-2
- rvm: jruby-19mode
- rvm: ruby-head
- rvm: jruby-head
allow_failures:
- rvm: rbx-2
env:
- GRAPE_VERSION=0.12.0
- GRAPE_VERSION=0.13.0
- GRAPE_VERSION=0.14.0
# - GRAPE_VERSION=HEAD
- rvm: jruby-19mode
- rvm: ruby-head
- rvm: jruby-head
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#406](https://github.com/ruby-grape/grape-swagger/pull/406): Force usage of entities for response definition [issue #385](https://github.com/ruby-grape/grape-swagger/issues/385) - [@LeFnord](https://github.com/LeFnord).
* [#405](https://github.com/ruby-grape/grape-swagger/pull/405), [#403](https://github.com/ruby-grape/grape-swagger/issues/403): Added version support matrix - [@LeFnord](https://github.com/LeFnord).
* [#408](https://github.com/ruby-grape/grape-swagger/pull/408): Added support for `HEAD` endpoints - [@Bugagazavr](https://github.com/Bugagazavr).
* [#407](https://github.com/ruby-grape/grape-swagger/issues/407): Added support for Grape 0.15.x - [@dblock](https://github.com/dblock).
* Your contribution here.

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'http://rubygems.org'

gemspec

case version = ENV['GRAPE_VERSION'] || '<= 0.14.0'
case version = ENV['GRAPE_VERSION'] || '~> 0.15.0'
when 'HEAD'
gem 'grape', github: 'ruby-grape/grape'
else
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ grape-swagger | swagger spec | grape | grape-entity
0.10.5 | 1.2 | >= 0.10.0 ... <= 0.14.0 | < 0.5.0
0.11.0 | 1.2 | >= 0.16.2 | < 0.5.0
0.20.1 | 2.0 | >= 0.12.0 ... <= 0.14.0 | <= 0.5.1
0.20.3 (next) | 2.0 | >= 0.12.0 ... <= 0.15.0 | <= 0.5.1

Swagger 2.0 support is currently not available for Grape 0.16.x. Please contribute to [#407](https://github.com/ruby-grape/grape-swagger/issues/407).

Expand Down
57 changes: 28 additions & 29 deletions example/api/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,40 @@ class Root < Grape::API
end

class Splines < Grape::API

@@splines = []

namespace :splines do
#
desc 'Get all splines',
is_array: true,
http_codes: [
{ code: 200, message: 'get Splines', model: Api::Entities::Splines },
{ code: 422, message: 'SplinesOutError' }
]
is_array: true,
http_codes: [
{ code: 200, message: 'get Splines', model: Api::Entities::Splines },
{ code: 422, message: 'SplinesOutError' }
]
get do
present :items, @@splines, with: Entities::Splines
end

#
desc 'Return a spline.',
http_codes: [
{ code: 200, message: 'get Splines' },
{ code: 422, message: 'SplinesOutError' }
]
http_codes: [
{ code: 200, message: 'get Splines' },
{ code: 422, message: 'SplinesOutError' }
]
params do
requires :id, type: Integer, desc: 'Spline id.'
end
get ':id' do
error!({ code: 422, message: 'SplinesOutError' }) unless @@splines[params[:id] - 1]
error!(code: 422, message: 'SplinesOutError') unless @@splines[params[:id] - 1]

present @@splines[params[:id] - 1], with: Entities::Splines
end

#
desc 'Create a spline.',
http_codes: [
{ code: 201, message: 'Spline created', model: Api::Entities::Splines }
]
http_codes: [
{ code: 201, message: 'Spline created', model: Api::Entities::Splines }
]
params do
requires :spline, type: Hash do
requires :x, type: Numeric
Expand All @@ -62,9 +61,9 @@ class Splines < Grape::API
end
post do
spline = Spline.new
spline.id = @@splines.size + 1
spline.x = (params[:spline][:x]/params[:spline][:y] || 0.0)
spline.y = (params[:spline][:y]/params[:spline][:x] || 0.0)
spline.id = @@splines.size + 1
spline.x = (params[:spline][:x] / params[:spline][:y] || 0.0)
spline.y = (params[:spline][:y] / params[:spline][:x] || 0.0)
spline.reticulated = params[:reticulated]

@@splines << spline
Expand All @@ -74,10 +73,10 @@ class Splines < Grape::API

#
desc 'Update a spline.',
http_codes: [
{ code: 200, message: 'update Splines', model: Api::Entities::Splines },
{ code: 422, message: 'SplinesOutError' }
]
http_codes: [
{ code: 200, message: 'update Splines', model: Api::Entities::Splines },
{ code: 422, message: 'SplinesOutError' }
]
params do
requires :id, type: Integer, desc: 'Spline id.'
optional :spline, type: Hash do
Expand All @@ -87,14 +86,14 @@ class Splines < Grape::API
optional :reticulated, type: Boolean, default: true, desc: 'True if the spline is reticulated.'
end
put ':id' do
error!({ code: 422, message: 'SplinesOutError' }) unless @@splines[params[:id] - 1]
error!(code: 422, message: 'SplinesOutError') unless @@splines[params[:id] - 1]

update_data = params[:spline]
spline = @@splines[params[:id] - 1]

spline.reticulated = !!update_data[:reticulated]
spline.x = update_data[:x]/update_data[:y] || 0.0
spline.y = update_data[:y]/update_data[:x] || 0.0
spline.x = update_data[:x] / update_data[:y] || 0.0
spline.y = update_data[:y] / update_data[:x] || 0.0

present spline, with: Entities::Splines
end
Expand All @@ -105,20 +104,20 @@ class Splines < Grape::API
requires :id, type: Integer, desc: 'Spline id.'
end
delete ':id' do
error!({ code: 422, message: 'SplinesOutError' }) unless @@splines[params[:id] - 1]
error!(code: 422, message: 'SplinesOutError') unless @@splines[params[:id] - 1]

@@splines.delete_at(params[:id] - 1)
{ "deleted": params[:id] }
{ 'deleted' => params[:id] }
end
end
end

class FileAccessor < Grape::API
namespace :file do
desc 'Update image',
details: "# TEST api for testing uploading\n
# curl --form file=@splines.png http://localhost:9292/file/upload",
content_type: 'application/octet-stream'
details: "# TEST api for testing uploading\n
# curl --form file=@splines.png http://localhost:9292/file/upload",
content_type: 'application/octet-stream'
post 'upload' do
filename = params[:file][:filename]
content_type 'binary', 'application/octet-stream'
Expand Down
2 changes: 1 addition & 1 deletion example/api/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Splines < Grape::Entity
expose :id, documentation: { type: Integer, desc: 'identity of a resource' }
expose :x, documentation: { type: Float, desc: 'x-value' }
expose :y, documentation: { type: Float, desc: 'y-value' }
expose :path, documentation: { type: String, desc: 'the requested resource'}
expose :path, documentation: { type: String, desc: 'the requested resource' }

private

Expand Down
12 changes: 5 additions & 7 deletions example/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ class Base < Grape::API
error_response(message: "Internal server error: #{e}", status: 500)
end

add_swagger_documentation :hide_documentation_path => true,
:api_version => 'v1',
:info => {
title: "Horses and Hussars",
description: "Demo app for dev of grape swagger 2.0"
add_swagger_documentation hide_documentation_path: true,
api_version: 'v1',
info: {
title: 'Horses and Hussars',
description: 'Demo app for dev of grape swagger 2.0'
}

end


run Base.new
2 changes: 1 addition & 1 deletion grape-swagger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.summary = 'A simple way to 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', '<= 0.14.0']
s.add_runtime_dependency 'grape', ['>= 0.12.0', '< 0.16.0']
s.add_runtime_dependency 'grape-entity'
s.add_runtime_dependency 'awesome_print'

Expand Down
8 changes: 4 additions & 4 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def path_item(routes, options)

verb, method_object = method_object(route, options, path)

if @paths.key?(path.to_sym)
@paths[path.to_sym][verb] = method_object
if @paths.key?(path.to_s)
@paths[path.to_s][verb] = method_object
else
@paths[path.to_sym] = { verb => method_object }
@paths[path.to_s] = { verb => method_object }
end

GrapeSwagger::DocMethods::Extensions.add(@paths[path.to_sym], @definitions, route)
GrapeSwagger::DocMethods::Extensions.add(@paths[path.to_s], @definitions, route)
end
end

Expand Down
Loading

0 comments on commit 819fcc5

Please sign in to comment.