Skip to content

Commit e977fea

Browse files
committed
Merge pull request #170 from dblock/grape-0.9.1
Ensure compatibility with Grape 0.8.0, 0.9.0 and 0.9.1.
2 parents e5302b0 + f9f87c5 commit e977fea

9 files changed

+63
-49
lines changed

.rubocop_todo.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
# This configuration was generated by `rubocop --auto-gen-config`
2-
# on 2014-11-10 14:38:32 -0500 using RuboCop version 0.27.0.
2+
# on 2014-11-10 15:12:48 -0500 using RuboCop version 0.27.0.
33
# The point is for the user to remove these configuration records
44
# one by one as the offenses are removed from the code base.
55
# Note that changes in the inspected code, or installation of new
66
# versions of RuboCop, may require this file to be generated again.
77

88
# Offense count: 8
99
Metrics/AbcSize:
10-
Max: 332
10+
Max: 327
1111

1212
# Offense count: 1
1313
# Configuration parameters: CountComments.
1414
Metrics/ClassLength:
15-
Max: 385
15+
Max: 387
1616

1717
# Offense count: 4
1818
Metrics/CyclomaticComplexity:
1919
Max: 92
2020

21-
# Offense count: 209
21+
# Offense count: 196
2222
# Configuration parameters: AllowURI, URISchemes.
2323
Metrics/LineLength:
2424
Max: 254
2525

26-
# Offense count: 11
26+
# Offense count: 12
2727
# Configuration parameters: CountComments.
2828
Metrics/MethodLength:
29-
Max: 354
29+
Max: 352
3030

3131
# Offense count: 4
3232
Metrics/PerceivedComplexity:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [#154](https://github.com/tim-vandecasteele/grape-swagger/pull/154): Allow classes for type declarations inside documentation - [@mrmargolis](https://github.com/mrmargolis).
55
* [#162](https://github.com/tim-vandecasteele/grape-swagger/pull/162): Fix performance issue related to having a large number of models - [@elado](https://github.com/elado).
66
* [#169](https://github.com/tim-vandecasteele/grape-swagger/pull/169): Test against multiple versions of Grape - [@dblock](https://github.com/dblock).
7+
* [#166](https://github.com/tim-vandecasteele/grape-swagger/pull/166): Ensure compatibility with Grape 0.8.0 or newer - [@dblock](https://github.com/dblock).
78
* Your contribution here.
89

910
### 0.8.0 (August 30, 2014)

grape-swagger.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
1111
s.summary = 'A simple way to 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'
14+
s.add_runtime_dependency 'grape', '>= 0.8.0'
1515
s.add_runtime_dependency 'grape-entity'
1616

1717
s.add_development_dependency 'rake'

lib/grape-swagger.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def add_swagger_documentation(options = {})
3535

3636
def combine_namespaces(app)
3737
app.endpoints.each do |endpoint|
38-
ns = endpoint.settings.stack.last[:namespace]
38+
ns = if endpoint.respond_to?(:namespace_stackable)
39+
endpoint.namespace_stackable(:namespace).last
40+
else
41+
endpoint.settings.stack.last[:namespace]
42+
end
3943
@combined_namespaces[ns.space] = ns if ns
4044

4145
combine_namespaces(endpoint.options[:app]) if endpoint.options[:app]
@@ -92,8 +96,7 @@ def self.setup(options)
9296
end
9397
end
9498

95-
desc api_doc.delete(:desc), params: api_doc.delete(:params)
96-
@last_description.merge!(api_doc)
99+
desc api_doc.delete(:desc), api_doc
97100
get @@mount_path do
98101
header['Access-Control-Allow-Origin'] = '*'
99102
header['Access-Control-Request-Method'] = '*'
@@ -132,14 +135,14 @@ def self.setup(options)
132135
output
133136
end
134137

135-
desc specific_api_doc.delete(:desc), params: {
138+
desc specific_api_doc.delete(:desc), { params: {
136139
'name' => {
137140
desc: 'Resource name of mounted API',
138141
type: 'string',
139142
required: true
140143
}
141-
}.merge(specific_api_doc.delete(:params) || {})
142-
@last_description.merge!(specific_api_doc)
144+
}.merge(specific_api_doc.delete(:params) || {}) }.merge(specific_api_doc)
145+
143146
get "#{@@mount_path}/:name" do
144147
header['Access-Control-Allow-Origin'] = '*'
145148
header['Access-Control-Request-Method'] = '*'
@@ -298,10 +301,10 @@ def parse_params(params, path, method)
298301
end
299302

300303
def content_types_for(target_class)
301-
content_types = (target_class.settings[:content_types] || {}).values
304+
content_types = (target_class.content_types || {}).values
302305

303306
if content_types.empty?
304-
formats = [target_class.settings[:format], target_class.settings[:default_format]].compact.uniq
307+
formats = [target_class.format, target_class.default_format].compact.uniq
305308
formats = Grape::Formatter::Base.formatters({}).keys if formats.empty?
306309
content_types = Grape::ContentTypes::CONTENT_TYPES.select { |content_type, _mime_type| formats.include? content_type }.values
307310
end

spec/form_params_spec.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ def app
3030
{}
3131
end
3232

33-
params do
34-
requires :required_group, type: Hash do
35-
requires :required_param_1
36-
requires :required_param_2
37-
end
38-
end
39-
post '/groups' do
40-
{}
41-
end
42-
4333
add_swagger_documentation
4434
end
4535
end
@@ -93,15 +83,4 @@ def app
9383
]
9484
}])
9585
end
96-
97-
it 'retrieves the documentation for group parameters' do
98-
get '/swagger_doc/groups.json'
99-
100-
body = JSON.parse last_response.body
101-
parameters = body['apis'].first['operations'].first['parameters']
102-
expect(parameters).to eq [
103-
{ 'paramType' => 'form', 'name' => 'required_group[required_param_1]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false },
104-
{ 'paramType' => 'form', 'name' => 'required_group[required_param_2]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false }]
105-
106-
end
10786
end

spec/group_params_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
3+
describe 'Group Params' do
4+
def app
5+
Class.new(Grape::API) do
6+
format :json
7+
8+
params do
9+
requires :required_group, type: Hash do
10+
requires :required_param_1
11+
requires :required_param_2
12+
end
13+
end
14+
post '/groups' do
15+
{}
16+
end
17+
18+
add_swagger_documentation
19+
end
20+
end
21+
22+
it 'retrieves the documentation for group parameters' do
23+
get '/swagger_doc/groups.json'
24+
25+
body = JSON.parse last_response.body
26+
parameters = body['apis'].first['operations'].first['parameters']
27+
expect(parameters).to eq [
28+
{ 'paramType' => 'form', 'name' => 'required_group[required_param_1]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false },
29+
{ 'paramType' => 'form', 'name' => 'required_group[required_param_2]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false }]
30+
end
31+
end

spec/hide_api_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def app
3636
'apiVersion' => '0.1',
3737
'swaggerVersion' => '1.2',
3838
'info' => {},
39-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
39+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
4040
'apis' => [
4141
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
4242
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
@@ -77,7 +77,7 @@ def app
7777
'apiVersion' => '0.1',
7878
'swaggerVersion' => '1.2',
7979
'info' => {},
80-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
80+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
8181
'apis' => [
8282
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
8383
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
@@ -92,7 +92,7 @@ def app
9292
'swaggerVersion' => '1.2',
9393
'basePath' => 'http://example.org',
9494
'resourcePath' => '/simple',
95-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
95+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
9696
'apis' => [{
9797
'path' => '/simple/show.{format}',
9898
'operations' => [{

spec/non_default_api_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def app
168168
'apiVersion' => '0.1',
169169
'swaggerVersion' => '1.2',
170170
'info' => {},
171-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
171+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
172172
'apis' => [
173173
{ 'path' => '/something.{format}', 'description' => 'Operations about somethings' },
174174
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
@@ -184,7 +184,7 @@ def app
184184
'swaggerVersion' => '1.2',
185185
'basePath' => 'http://example.org',
186186
'resourcePath' => '/something',
187-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
187+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
188188
'apis' => [{
189189
'path' => '/0.1/something.{format}',
190190
'operations' => [{
@@ -229,7 +229,7 @@ def app
229229
'apiVersion' => '0.1',
230230
'swaggerVersion' => '1.2',
231231
'info' => {},
232-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
232+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
233233
'apis' => [
234234
{ 'path' => '/something.{format}', 'description' => 'Operations about somethings' }
235235
]
@@ -269,7 +269,7 @@ def app
269269
'swaggerVersion' => '1.2',
270270
'basePath' => 'http://example.org',
271271
'resourcePath' => '/something',
272-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
272+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
273273
'apis' => [{
274274
'path' => '/abc/something.{format}',
275275
'operations' => [{
@@ -320,7 +320,7 @@ def app
320320
'swaggerVersion' => '1.2',
321321
'basePath' => 'http://example.org',
322322
'resourcePath' => '/something',
323-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
323+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
324324
'apis' => [{
325325
'path' => '/abc/v20/something.{format}',
326326
'operations' => [{
@@ -561,7 +561,7 @@ def app
561561
'apiVersion' => '0.1',
562562
'swaggerVersion' => '1.2',
563563
'info' => {},
564-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
564+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
565565
'apis' => [
566566
{ 'path' => '/first.{format}', 'description' => 'Operations about firsts' }
567567
]
@@ -574,7 +574,7 @@ def app
574574
'apiVersion' => '0.1',
575575
'swaggerVersion' => '1.2',
576576
'info' => {},
577-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
577+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
578578
'apis' => [
579579
{ 'path' => '/second.{format}', 'description' => 'Operations about seconds' }
580580
]

spec/simple_mounted_api_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def app
7272
'apiVersion' => '0.1',
7373
'swaggerVersion' => '1.2',
7474
'info' => {},
75-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
75+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
7676
'apis' => [
7777
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
7878
{ 'path' => '/simple-test.{format}', 'description' => 'Operations about simple-tests' },
@@ -91,7 +91,7 @@ def app
9191
'swaggerVersion' => '1.2',
9292
'basePath' => 'http://example.org',
9393
'resourcePath' => '/simple',
94-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
94+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
9595
'apis' => [{
9696
'path' => '/simple.{format}',
9797
'operations' => [{
@@ -114,7 +114,7 @@ def app
114114
'swaggerVersion' => '1.2',
115115
'basePath' => 'http://example.org',
116116
'resourcePath' => '/simple-test',
117-
'produces' => ['application/xml', 'application/json', 'application/vnd.api+json', 'text/plain'],
117+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
118118
'apis' => [{
119119
'path' => '/simple-test.{format}',
120120
'operations' => [{

0 commit comments

Comments
 (0)