grape-swagger 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -33
- data/.rubocop_todo.yml +55 -0
- data/.travis.yml +12 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile +8 -1
- data/README.md +10 -8
- data/{test → example}/api.rb +4 -0
- data/{test → example}/config.ru +0 -0
- data/{test → example}/splines.png +0 -0
- data/grape-swagger.gemspec +2 -2
- data/lib/grape-swagger.rb +211 -193
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/api_global_models_spec.rb +10 -7
- data/spec/api_models_spec.rb +45 -17
- data/spec/api_paths_spec.rb +67 -0
- data/spec/api_root_spec.rb +31 -0
- data/spec/boolean_params_spec.rb +30 -0
- data/spec/form_params_spec.rb +7 -43
- data/spec/grape-swagger_helper_spec.rb +1 -23
- data/spec/group_params_spec.rb +31 -0
- data/spec/hash_params_spec.rb +30 -0
- data/spec/hide_api_spec.rb +3 -3
- data/spec/non_default_api_spec.rb +25 -22
- data/spec/response_model_spec.rb +42 -11
- data/spec/simple_mounted_api_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- metadata +20 -12
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Hash Params' do
|
4
|
+
def app
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
format :json
|
7
|
+
|
8
|
+
params do
|
9
|
+
requires :a_hash, type: Hash
|
10
|
+
end
|
11
|
+
post :splines do
|
12
|
+
end
|
13
|
+
|
14
|
+
add_swagger_documentation
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
subject do
|
19
|
+
get '/swagger_doc/splines'
|
20
|
+
expect(last_response.status).to eq 200
|
21
|
+
body = JSON.parse last_response.body
|
22
|
+
body['apis'].first['operations'].first['parameters']
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'declares hash types as object' do
|
26
|
+
expect(subject).to eq [
|
27
|
+
{ 'paramType' => 'form', 'name' => 'a_hash', 'description' => nil, 'type' => 'object', 'required' => true, 'allowMultiple' => false }
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
data/spec/hide_api_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe 'a hide mounted api' do
|
|
36
36
|
'apiVersion' => '0.1',
|
37
37
|
'swaggerVersion' => '1.2',
|
38
38
|
'info' => {},
|
39
|
-
'produces' =>
|
39
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
40
40
|
'apis' => [
|
41
41
|
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
|
42
42
|
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
@@ -77,7 +77,7 @@ describe 'a hide mounted api with same namespace' do
|
|
77
77
|
'apiVersion' => '0.1',
|
78
78
|
'swaggerVersion' => '1.2',
|
79
79
|
'info' => {},
|
80
|
-
'produces' =>
|
80
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
81
81
|
'apis' => [
|
82
82
|
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
|
83
83
|
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
@@ -92,7 +92,7 @@ describe 'a hide mounted api with same namespace' do
|
|
92
92
|
'swaggerVersion' => '1.2',
|
93
93
|
'basePath' => 'http://example.org',
|
94
94
|
'resourcePath' => '/simple',
|
95
|
-
'produces' =>
|
95
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
96
96
|
'apis' => [{
|
97
97
|
'path' => '/simple/show.{format}',
|
98
98
|
'operations' => [{
|
@@ -50,7 +50,7 @@ describe 'options: ' do
|
|
50
50
|
|
51
51
|
class SimpleApiWithProcBasePath < Grape::API
|
52
52
|
mount ProcBasePathMountedApi
|
53
|
-
add_swagger_documentation base_path: proc { |request|
|
53
|
+
add_swagger_documentation base_path: proc { |request| [request.base_url, request.params[:base_path], 'some_value'].compact.join('/') }
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -58,18 +58,26 @@ describe 'options: ' do
|
|
58
58
|
SimpleApiWithProcBasePath
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
context 'default' do
|
62
|
+
subject do
|
63
|
+
get '/swagger_doc/something.json'
|
64
|
+
JSON.parse(last_response.body)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'retrieves the same given base-path for mounted-api' do
|
68
|
+
expect(subject['basePath']).to eq 'http://example.org/some_value'
|
69
|
+
end
|
64
70
|
end
|
65
71
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
72
|
+
context 'param' do
|
73
|
+
subject do
|
74
|
+
get '/swagger_doc/something.json?base_path=foobar'
|
75
|
+
JSON.parse(last_response.body)
|
76
|
+
end
|
70
77
|
|
71
|
-
|
72
|
-
|
78
|
+
it 're-evaluates base-path' do
|
79
|
+
expect(subject['basePath']).to eq 'http://example.org/foobar/some_value'
|
80
|
+
end
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
@@ -97,11 +105,6 @@ describe 'options: ' do
|
|
97
105
|
JSON.parse(last_response.body)
|
98
106
|
end
|
99
107
|
|
100
|
-
# it "retrieves the given base-path on /swagger_doc" do
|
101
|
-
# get '/swagger_doc.json'
|
102
|
-
# JSON.parse(last_response.body)["basePath"].should == "http://example.org/some_value"
|
103
|
-
# end
|
104
|
-
|
105
108
|
it 'retrieves the same given base-path for mounted-api' do
|
106
109
|
get '/swagger_doc/something.json'
|
107
110
|
expect(subject['basePath']).to eq 'http://example.org/some_value'
|
@@ -168,7 +171,7 @@ describe 'options: ' do
|
|
168
171
|
'apiVersion' => '0.1',
|
169
172
|
'swaggerVersion' => '1.2',
|
170
173
|
'info' => {},
|
171
|
-
'produces' =>
|
174
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
172
175
|
'apis' => [
|
173
176
|
{ 'path' => '/something.{format}', 'description' => 'Operations about somethings' },
|
174
177
|
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
@@ -184,7 +187,7 @@ describe 'options: ' do
|
|
184
187
|
'swaggerVersion' => '1.2',
|
185
188
|
'basePath' => 'http://example.org',
|
186
189
|
'resourcePath' => '/something',
|
187
|
-
'produces' =>
|
190
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
188
191
|
'apis' => [{
|
189
192
|
'path' => '/0.1/something.{format}',
|
190
193
|
'operations' => [{
|
@@ -229,7 +232,7 @@ describe 'options: ' do
|
|
229
232
|
'apiVersion' => '0.1',
|
230
233
|
'swaggerVersion' => '1.2',
|
231
234
|
'info' => {},
|
232
|
-
'produces' =>
|
235
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
233
236
|
'apis' => [
|
234
237
|
{ 'path' => '/something.{format}', 'description' => 'Operations about somethings' }
|
235
238
|
]
|
@@ -269,7 +272,7 @@ describe 'options: ' do
|
|
269
272
|
'swaggerVersion' => '1.2',
|
270
273
|
'basePath' => 'http://example.org',
|
271
274
|
'resourcePath' => '/something',
|
272
|
-
'produces' =>
|
275
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
273
276
|
'apis' => [{
|
274
277
|
'path' => '/abc/something.{format}',
|
275
278
|
'operations' => [{
|
@@ -320,7 +323,7 @@ describe 'options: ' do
|
|
320
323
|
'swaggerVersion' => '1.2',
|
321
324
|
'basePath' => 'http://example.org',
|
322
325
|
'resourcePath' => '/something',
|
323
|
-
'produces' =>
|
326
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
324
327
|
'apis' => [{
|
325
328
|
'path' => '/abc/v20/something.{format}',
|
326
329
|
'operations' => [{
|
@@ -561,7 +564,7 @@ describe 'options: ' do
|
|
561
564
|
'apiVersion' => '0.1',
|
562
565
|
'swaggerVersion' => '1.2',
|
563
566
|
'info' => {},
|
564
|
-
'produces' =>
|
567
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
565
568
|
'apis' => [
|
566
569
|
{ 'path' => '/first.{format}', 'description' => 'Operations about firsts' }
|
567
570
|
]
|
@@ -574,7 +577,7 @@ describe 'options: ' do
|
|
574
577
|
'apiVersion' => '0.1',
|
575
578
|
'swaggerVersion' => '1.2',
|
576
579
|
'info' => {},
|
577
|
-
'produces' =>
|
580
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
578
581
|
'apis' => [
|
579
582
|
{ 'path' => '/second.{format}', 'description' => 'Operations about seconds' }
|
580
583
|
]
|
data/spec/response_model_spec.rb
CHANGED
@@ -4,17 +4,21 @@ describe 'responseModel' do
|
|
4
4
|
before :all do
|
5
5
|
module MyAPI
|
6
6
|
module Entities
|
7
|
-
class
|
8
|
-
|
9
|
-
name.sub(/^MyAPI::Entities::/, '')
|
10
|
-
end
|
7
|
+
class Kind < Grape::Entity
|
8
|
+
expose :title, documentation: { type: 'string', desc: 'Title of the kind.' }
|
11
9
|
end
|
12
10
|
|
13
|
-
class Something <
|
11
|
+
class Something < Grape::Entity
|
14
12
|
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
13
|
+
expose :kind, using: Kind, documentation: { type: 'MyAPI::Kind', desc: 'The kind of this something.' }
|
14
|
+
expose :relation, using: 'MyAPI::Entities::Relation', documentation: { type: 'MyAPI::Relation', desc: 'A related model.' }
|
15
|
+
end
|
16
|
+
|
17
|
+
class Relation < Grape::Entity
|
18
|
+
expose :name, documentation: { type: 'string', desc: 'Name' }
|
15
19
|
end
|
16
20
|
|
17
|
-
class Error <
|
21
|
+
class Error < Grape::Entity
|
18
22
|
expose :code, documentation: { type: 'string', desc: 'Error code' }
|
19
23
|
expose :message, documentation: { type: 'string', desc: 'Error message' }
|
20
24
|
end
|
@@ -59,22 +63,49 @@ describe 'responseModel' do
|
|
59
63
|
{
|
60
64
|
'code' => 200,
|
61
65
|
'message' => 'OK',
|
62
|
-
'responseModel' => 'Something'
|
66
|
+
'responseModel' => 'MyAPI::Something'
|
63
67
|
},
|
64
68
|
{
|
65
69
|
'code' => 403,
|
66
70
|
'message' => 'Refused to return something',
|
67
|
-
'responseModel' => 'Error'
|
71
|
+
'responseModel' => 'MyAPI::Error'
|
68
72
|
}
|
69
73
|
]
|
70
74
|
)
|
71
|
-
|
72
|
-
expect(subject['models']
|
73
|
-
|
75
|
+
|
76
|
+
expect(subject['models'].keys).to include 'MyAPI::Error'
|
77
|
+
expect(subject['models']['MyAPI::Error']).to eq(
|
78
|
+
'id' => 'MyAPI::Error',
|
74
79
|
'properties' => {
|
75
80
|
'code' => { 'type' => 'string', 'description' => 'Error code' },
|
76
81
|
'message' => { 'type' => 'string', 'description' => 'Error message' }
|
77
82
|
}
|
78
83
|
)
|
84
|
+
|
85
|
+
expect(subject['models'].keys).to include 'MyAPI::Something'
|
86
|
+
expect(subject['models']['MyAPI::Something']).to eq(
|
87
|
+
'id' => 'MyAPI::Something',
|
88
|
+
'properties' => {
|
89
|
+
'text' => { 'type' => 'string', 'description' => 'Content of something.' },
|
90
|
+
'kind' => { '$ref' => 'MyAPI::Kind', 'description' => 'The kind of this something.' },
|
91
|
+
'relation' => { '$ref' => 'MyAPI::Relation', 'description' => 'A related model.' }
|
92
|
+
}
|
93
|
+
)
|
94
|
+
|
95
|
+
expect(subject['models'].keys).to include 'MyAPI::Kind'
|
96
|
+
expect(subject['models']['MyAPI::Kind']).to eq(
|
97
|
+
'id' => 'MyAPI::Kind',
|
98
|
+
'properties' => {
|
99
|
+
'title' => { 'type' => 'string', 'description' => 'Title of the kind.' }
|
100
|
+
}
|
101
|
+
)
|
102
|
+
|
103
|
+
expect(subject['models'].keys).to include 'MyAPI::Relation'
|
104
|
+
expect(subject['models']['MyAPI::Relation']).to eq(
|
105
|
+
'id' => 'MyAPI::Relation',
|
106
|
+
'properties' => {
|
107
|
+
'name' => { 'type' => 'string', 'description' => 'Name' }
|
108
|
+
}
|
109
|
+
)
|
79
110
|
end
|
80
111
|
end
|
@@ -72,7 +72,7 @@ describe 'a simple mounted api' do
|
|
72
72
|
'apiVersion' => '0.1',
|
73
73
|
'swaggerVersion' => '1.2',
|
74
74
|
'info' => {},
|
75
|
-
'produces' =>
|
75
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
76
76
|
'apis' => [
|
77
77
|
{ 'path' => '/simple.{format}', 'description' => 'Operations about simples' },
|
78
78
|
{ 'path' => '/simple-test.{format}', 'description' => 'Operations about simple-tests' },
|
@@ -91,7 +91,7 @@ describe 'a simple mounted api' do
|
|
91
91
|
'swaggerVersion' => '1.2',
|
92
92
|
'basePath' => 'http://example.org',
|
93
93
|
'resourcePath' => '/simple',
|
94
|
-
'produces' =>
|
94
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
95
95
|
'apis' => [{
|
96
96
|
'path' => '/simple.{format}',
|
97
97
|
'operations' => [{
|
@@ -114,7 +114,7 @@ describe 'a simple mounted api' do
|
|
114
114
|
'swaggerVersion' => '1.2',
|
115
115
|
'basePath' => 'http://example.org',
|
116
116
|
'resourcePath' => '/simple-test',
|
117
|
-
'produces' =>
|
117
|
+
'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq,
|
118
118
|
'apis' => [{
|
119
119
|
'path' => '/simple-test.{format}',
|
120
120
|
'operations' => [{
|
data/spec/spec_helper.rb
CHANGED
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.9.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: 2014-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: grape-entity
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.27.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.27.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: kramdown
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- ".gitignore"
|
204
204
|
- ".rspec"
|
205
205
|
- ".rubocop.yml"
|
206
|
+
- ".rubocop_todo.yml"
|
206
207
|
- ".ruby-gemset"
|
207
208
|
- ".ruby-version"
|
208
209
|
- ".travis.yml"
|
@@ -214,6 +215,9 @@ files:
|
|
214
215
|
- RELEASING.md
|
215
216
|
- Rakefile
|
216
217
|
- UPGRADING.md
|
218
|
+
- example/api.rb
|
219
|
+
- example/config.ru
|
220
|
+
- example/splines.png
|
217
221
|
- grape-swagger.gemspec
|
218
222
|
- lib/grape-swagger.rb
|
219
223
|
- lib/grape-swagger/errors.rb
|
@@ -224,10 +228,15 @@ files:
|
|
224
228
|
- spec/api_description_spec.rb
|
225
229
|
- spec/api_global_models_spec.rb
|
226
230
|
- spec/api_models_spec.rb
|
231
|
+
- spec/api_paths_spec.rb
|
232
|
+
- spec/api_root_spec.rb
|
233
|
+
- spec/boolean_params_spec.rb
|
227
234
|
- spec/default_api_spec.rb
|
228
235
|
- spec/form_params_spec.rb
|
229
236
|
- spec/grape-swagger_helper_spec.rb
|
230
237
|
- spec/grape-swagger_spec.rb
|
238
|
+
- spec/group_params_spec.rb
|
239
|
+
- spec/hash_params_spec.rb
|
231
240
|
- spec/hide_api_spec.rb
|
232
241
|
- spec/markdown/kramdown_adapter_spec.rb
|
233
242
|
- spec/markdown/markdown_spec.rb
|
@@ -238,9 +247,6 @@ files:
|
|
238
247
|
- spec/simple_mounted_api_spec.rb
|
239
248
|
- spec/spec_helper.rb
|
240
249
|
- spec/version_spec.rb
|
241
|
-
- test/api.rb
|
242
|
-
- test/config.ru
|
243
|
-
- test/splines.png
|
244
250
|
homepage: https://github.com/tim-vandecasteele/grape-swagger
|
245
251
|
licenses:
|
246
252
|
- MIT
|
@@ -270,10 +276,15 @@ test_files:
|
|
270
276
|
- spec/api_description_spec.rb
|
271
277
|
- spec/api_global_models_spec.rb
|
272
278
|
- spec/api_models_spec.rb
|
279
|
+
- spec/api_paths_spec.rb
|
280
|
+
- spec/api_root_spec.rb
|
281
|
+
- spec/boolean_params_spec.rb
|
273
282
|
- spec/default_api_spec.rb
|
274
283
|
- spec/form_params_spec.rb
|
275
284
|
- spec/grape-swagger_helper_spec.rb
|
276
285
|
- spec/grape-swagger_spec.rb
|
286
|
+
- spec/group_params_spec.rb
|
287
|
+
- spec/hash_params_spec.rb
|
277
288
|
- spec/hide_api_spec.rb
|
278
289
|
- spec/markdown/kramdown_adapter_spec.rb
|
279
290
|
- spec/markdown/markdown_spec.rb
|
@@ -284,6 +295,3 @@ test_files:
|
|
284
295
|
- spec/simple_mounted_api_spec.rb
|
285
296
|
- spec/spec_helper.rb
|
286
297
|
- spec/version_spec.rb
|
287
|
-
- test/api.rb
|
288
|
-
- test/config.ru
|
289
|
-
- test/splines.png
|