grape-swagger 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +13 -13
- data/.travis.yml +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +49 -2
- data/UPGRADING.md +20 -0
- data/lib/grape-swagger.rb +149 -23
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/api_global_models_spec.rb +0 -2
- data/spec/api_models_spec.rb +39 -3
- data/spec/api_paths_spec.rb +0 -3
- data/spec/api_root_spec.rb +0 -1
- data/spec/api_with_path_versioning_spec.rb +33 -0
- data/spec/api_with_standalone_namespace_spec.rb +215 -0
- data/spec/array_params_spec.rb +34 -0
- data/spec/float_api_spec.rb +30 -0
- data/spec/form_params_spec.rb +15 -0
- data/spec/grape-swagger_helper_spec.rb +18 -3
- data/spec/hide_api_spec.rb +15 -0
- data/spec/markdown/kramdown_adapter_spec.rb +0 -1
- data/spec/markdown/redcarpet_adapter_spec.rb +0 -1
- data/spec/mutually_exclusive_spec.rb +36 -0
- data/spec/non_default_api_spec.rb +0 -5
- data/spec/range_values_spec.rb +49 -0
- data/spec/response_model_spec.rb +10 -0
- metadata +14 -2
data/spec/form_params_spec.rb
CHANGED
@@ -30,6 +30,15 @@ describe 'Form Params' do
|
|
30
30
|
{}
|
31
31
|
end
|
32
32
|
|
33
|
+
params do
|
34
|
+
requires :id, type: Integer, desc: 'id of item'
|
35
|
+
requires :name, type: String, desc: 'name of item'
|
36
|
+
optional :conditions, type: Symbol, desc: 'conditions of item', values: [:one, :two]
|
37
|
+
end
|
38
|
+
post '/items/:id' do
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
33
42
|
add_swagger_documentation
|
34
43
|
end
|
35
44
|
end
|
@@ -46,5 +55,11 @@ describe 'Form Params' do
|
|
46
55
|
expect(subject['apis'][1]['path']).to start_with '/items/{id}'
|
47
56
|
expect(subject['apis'][1]['operations'][0]['method']).to eq 'PUT'
|
48
57
|
expect(subject['apis'][1]['operations'][1]['method']).to eq 'PATCH'
|
58
|
+
expect(subject['apis'][1]['operations'][2]['method']).to eq 'POST'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'treats Symbol parameter as form param' do
|
62
|
+
expect(subject['apis'][1]['operations'][2]['parameters'][2]['paramType']).to eq 'form'
|
63
|
+
expect(subject['apis'][1]['operations'][2]['parameters'][2]['type']).to eq 'string'
|
49
64
|
end
|
50
65
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'helpers' do
|
4
|
-
|
5
4
|
before :all do
|
6
5
|
class HelperTestAPI < Grape::API
|
7
6
|
end
|
@@ -59,7 +58,25 @@ describe 'helpers' do
|
|
59
58
|
allowMultiple: false
|
60
59
|
}
|
61
60
|
]
|
61
|
+
end
|
62
62
|
|
63
|
+
it 'parses symbol param as string' do
|
64
|
+
params = {
|
65
|
+
animal: { type: 'Symbol', desc: 'An animal you like', required: true, values: [:cat, :dog] }
|
66
|
+
}
|
67
|
+
path = '/coolness'
|
68
|
+
method = 'POST'
|
69
|
+
expect(subject.parse_params(params, path, method)).to eq [
|
70
|
+
{
|
71
|
+
paramType: 'form',
|
72
|
+
name: :animal,
|
73
|
+
description: 'An animal you like',
|
74
|
+
type: 'string',
|
75
|
+
required: true,
|
76
|
+
allowMultiple: false,
|
77
|
+
enum: [:cat, :dog]
|
78
|
+
}
|
79
|
+
]
|
63
80
|
end
|
64
81
|
|
65
82
|
context 'custom type' do
|
@@ -78,7 +95,6 @@ describe 'helpers' do
|
|
78
95
|
]
|
79
96
|
end
|
80
97
|
end
|
81
|
-
|
82
98
|
end
|
83
99
|
|
84
100
|
context 'parsing the path' do
|
@@ -120,5 +136,4 @@ describe 'helpers' do
|
|
120
136
|
]
|
121
137
|
end
|
122
138
|
end
|
123
|
-
|
124
139
|
end
|
data/spec/hide_api_spec.rb
CHANGED
@@ -14,6 +14,13 @@ describe 'a hide mounted api' do
|
|
14
14
|
get '/hide' do
|
15
15
|
{ foo: 'bar' }
|
16
16
|
end
|
17
|
+
|
18
|
+
desc 'Lazily show endpoint',
|
19
|
+
hidden: -> { false }
|
20
|
+
|
21
|
+
get '/lazy' do
|
22
|
+
{ foo: 'bar' }
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
class HideApi < Grape::API
|
@@ -39,6 +46,7 @@ describe 'a hide mounted api' do
|
|
39
46
|
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
40
47
|
'apis' => [
|
41
48
|
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
|
49
|
+
{ 'path' => '/lazy.{format}', 'description' => 'Operations about lazies' },
|
42
50
|
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
43
51
|
]
|
44
52
|
)
|
@@ -59,6 +67,13 @@ describe 'a hide mounted api with same namespace' do
|
|
59
67
|
get '/simple/hide' do
|
60
68
|
{ foo: 'bar' }
|
61
69
|
end
|
70
|
+
|
71
|
+
desc 'Lazily hide endpoint',
|
72
|
+
hidden: -> { true }
|
73
|
+
|
74
|
+
get '/simple/lazy' do
|
75
|
+
{ foo: 'bar' }
|
76
|
+
end
|
62
77
|
end
|
63
78
|
|
64
79
|
class HideNamespaceApi < Grape::API
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mutually exclusive 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
|
+
group :param_group_1, type: Hash do
|
11
|
+
requires :param_1, type: String
|
12
|
+
end
|
13
|
+
optional :param_group_2, type: Array do
|
14
|
+
requires :param_2, type: String
|
15
|
+
end
|
16
|
+
mutually_exclusive :param_group_1, :param_group_2
|
17
|
+
end
|
18
|
+
end
|
19
|
+
post '/groups' do
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
add_swagger_documentation
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'marks the nested required params in a group as optional if the group is in a mutually_exclusive set' do
|
28
|
+
get '/swagger_doc/groups'
|
29
|
+
|
30
|
+
body = JSON.parse last_response.body
|
31
|
+
parameters = body['apis'].first['operations'].first['parameters']
|
32
|
+
expect(parameters).to eq [
|
33
|
+
{ 'paramType' => 'form', 'name' => 'required_group[param_group_1][param_1]', 'description' => nil, 'type' => 'string', 'required' => false, 'allowMultiple' => false },
|
34
|
+
{ 'paramType' => 'form', 'name' => 'required_group[param_group_2][][param_2]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false }]
|
35
|
+
end
|
36
|
+
end
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe 'options: ' do
|
4
4
|
context 'overriding the basepath' do
|
5
5
|
before :all do
|
6
|
-
|
7
6
|
class BasePathMountedApi < Grape::API
|
8
7
|
desc 'This gets something.'
|
9
8
|
get '/something' do
|
@@ -17,7 +16,6 @@ describe 'options: ' do
|
|
17
16
|
mount BasePathMountedApi
|
18
17
|
add_swagger_documentation base_path: NON_DEFAULT_BASE_PATH
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
|
23
21
|
def app
|
@@ -254,7 +252,6 @@ describe 'options: ' do
|
|
254
252
|
mount HideDocumentationPathPrefixedMountedApi
|
255
253
|
add_swagger_documentation hide_documentation_path: true
|
256
254
|
end
|
257
|
-
|
258
255
|
end
|
259
256
|
|
260
257
|
def app
|
@@ -286,7 +283,6 @@ describe 'options: ' do
|
|
286
283
|
}]
|
287
284
|
)
|
288
285
|
end
|
289
|
-
|
290
286
|
end
|
291
287
|
|
292
288
|
context 'overriding hiding the documentation paths in prefixed and versioned API' do
|
@@ -338,7 +334,6 @@ describe 'options: ' do
|
|
338
334
|
}]
|
339
335
|
)
|
340
336
|
end
|
341
|
-
|
342
337
|
end
|
343
338
|
|
344
339
|
context 'overriding the mount-path' do
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Range Params' do
|
4
|
+
def app
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
format :json
|
7
|
+
|
8
|
+
params do
|
9
|
+
requires :letter, type: String, values: 'a'..'z'
|
10
|
+
end
|
11
|
+
post :letter do
|
12
|
+
end
|
13
|
+
|
14
|
+
params do
|
15
|
+
requires :number, type: Integer, values: -5..5
|
16
|
+
end
|
17
|
+
post :integer do
|
18
|
+
end
|
19
|
+
|
20
|
+
add_swagger_documentation
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
subject(:letter) do
|
25
|
+
get '/swagger_doc/letter'
|
26
|
+
expect(last_response.status).to eq 200
|
27
|
+
body = JSON.parse last_response.body
|
28
|
+
body['apis'].first['operations'].first['parameters']
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has letter range values' do
|
32
|
+
expect(letter).to eq [
|
33
|
+
{ 'paramType' => 'form', 'name' => 'letter', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false, 'enum' => ('a'..'z').to_a }
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
subject(:number) do
|
38
|
+
get '/swagger_doc/integer'
|
39
|
+
expect(last_response.status).to eq 200
|
40
|
+
body = JSON.parse last_response.body
|
41
|
+
body['apis'].first['operations'].first['parameters']
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has number range values' do
|
45
|
+
expect(number).to eq [
|
46
|
+
{ 'paramType' => 'form', 'name' => 'number', 'description' => nil, 'type' => 'integer', 'required' => true, 'allowMultiple' => false, 'format' => 'int32', 'enum' => (-5..5).to_a }
|
47
|
+
]
|
48
|
+
end
|
49
|
+
end
|
data/spec/response_model_spec.rb
CHANGED
@@ -11,6 +11,9 @@ describe 'responseModel' do
|
|
11
11
|
class Something < Grape::Entity
|
12
12
|
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
13
13
|
expose :kind, using: Kind, documentation: { type: 'MyAPI::Kind', desc: 'The kind of this something.' }
|
14
|
+
expose :kind2, using: Kind, documentation: { desc: 'Secondary kind.' }
|
15
|
+
expose :kind3, using: 'MyAPI::Entities::Kind', documentation: { desc: 'Tertiary kind.' }
|
16
|
+
expose :tags, using: 'MyAPI::Entities::Tag', documentation: { desc: 'Tags.', is_array: true }
|
14
17
|
expose :relation, using: 'MyAPI::Entities::Relation', documentation: { type: 'MyAPI::Relation', desc: 'A related model.' }
|
15
18
|
end
|
16
19
|
|
@@ -18,6 +21,10 @@ describe 'responseModel' do
|
|
18
21
|
expose :name, documentation: { type: 'string', desc: 'Name' }
|
19
22
|
end
|
20
23
|
|
24
|
+
class Tag < Grape::Entity
|
25
|
+
expose :name, documentation: { type: 'string', desc: 'Name' }
|
26
|
+
end
|
27
|
+
|
21
28
|
class Error < Grape::Entity
|
22
29
|
expose :code, documentation: { type: 'string', desc: 'Error code' }
|
23
30
|
expose :message, documentation: { type: 'string', desc: 'Error message' }
|
@@ -88,6 +95,9 @@ describe 'responseModel' do
|
|
88
95
|
'properties' => {
|
89
96
|
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
90
97
|
'kind' => { '$ref' => 'MyAPI::Kind', 'description' => 'The kind of this something.' },
|
98
|
+
'kind2' => { '$ref' => 'MyAPI::Kind', 'description' => 'Secondary kind.' },
|
99
|
+
'kind3' => { '$ref' => 'MyAPI::Kind', 'description' => 'Tertiary kind.' },
|
100
|
+
'tags' => { 'items' => { '$ref' => 'MyAPI::Tag' }, 'type' => 'array', 'description' => 'Tags.' },
|
91
101
|
'relation' => { '$ref' => 'MyAPI::Relation', 'description' => 'A related model.' }
|
92
102
|
}
|
93
103
|
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Vandecasteele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -230,8 +230,12 @@ files:
|
|
230
230
|
- spec/api_models_spec.rb
|
231
231
|
- spec/api_paths_spec.rb
|
232
232
|
- spec/api_root_spec.rb
|
233
|
+
- spec/api_with_path_versioning_spec.rb
|
234
|
+
- spec/api_with_standalone_namespace_spec.rb
|
235
|
+
- spec/array_params_spec.rb
|
233
236
|
- spec/boolean_params_spec.rb
|
234
237
|
- spec/default_api_spec.rb
|
238
|
+
- spec/float_api_spec.rb
|
235
239
|
- spec/form_params_spec.rb
|
236
240
|
- spec/grape-swagger_helper_spec.rb
|
237
241
|
- spec/grape-swagger_spec.rb
|
@@ -241,8 +245,10 @@ files:
|
|
241
245
|
- spec/markdown/kramdown_adapter_spec.rb
|
242
246
|
- spec/markdown/markdown_spec.rb
|
243
247
|
- spec/markdown/redcarpet_adapter_spec.rb
|
248
|
+
- spec/mutually_exclusive_spec.rb
|
244
249
|
- spec/namespaced_api_spec.rb
|
245
250
|
- spec/non_default_api_spec.rb
|
251
|
+
- spec/range_values_spec.rb
|
246
252
|
- spec/response_model_spec.rb
|
247
253
|
- spec/simple_mounted_api_spec.rb
|
248
254
|
- spec/spec_helper.rb
|
@@ -278,8 +284,12 @@ test_files:
|
|
278
284
|
- spec/api_models_spec.rb
|
279
285
|
- spec/api_paths_spec.rb
|
280
286
|
- spec/api_root_spec.rb
|
287
|
+
- spec/api_with_path_versioning_spec.rb
|
288
|
+
- spec/api_with_standalone_namespace_spec.rb
|
289
|
+
- spec/array_params_spec.rb
|
281
290
|
- spec/boolean_params_spec.rb
|
282
291
|
- spec/default_api_spec.rb
|
292
|
+
- spec/float_api_spec.rb
|
283
293
|
- spec/form_params_spec.rb
|
284
294
|
- spec/grape-swagger_helper_spec.rb
|
285
295
|
- spec/grape-swagger_spec.rb
|
@@ -289,8 +299,10 @@ test_files:
|
|
289
299
|
- spec/markdown/kramdown_adapter_spec.rb
|
290
300
|
- spec/markdown/markdown_spec.rb
|
291
301
|
- spec/markdown/redcarpet_adapter_spec.rb
|
302
|
+
- spec/mutually_exclusive_spec.rb
|
292
303
|
- spec/namespaced_api_spec.rb
|
293
304
|
- spec/non_default_api_spec.rb
|
305
|
+
- spec/range_values_spec.rb
|
294
306
|
- spec/response_model_spec.rb
|
295
307
|
- spec/simple_mounted_api_spec.rb
|
296
308
|
- spec/spec_helper.rb
|