grape-swagger 0.9.0 → 0.10.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_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
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Global Models' do
|
4
|
-
|
5
4
|
before :all do
|
6
5
|
module Entities
|
7
6
|
module Some
|
@@ -74,6 +73,5 @@ describe 'Global Models' do
|
|
74
73
|
'created_at' => { 'type' => 'dateTime', 'description' => 'Creation of something.' }
|
75
74
|
}
|
76
75
|
})
|
77
|
-
|
78
76
|
end
|
79
77
|
end
|
data/spec/api_models_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'API Models' do
|
4
|
-
|
5
4
|
before :all do
|
6
5
|
module Entities
|
7
6
|
class Something < Grape::Entity
|
@@ -72,6 +71,29 @@ describe 'API Models' do
|
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
74
|
+
module Entities
|
75
|
+
class QueryInputElement < Grape::Entity
|
76
|
+
expose :key, documentation: {
|
77
|
+
type: String, desc: 'Name of parameter', required: true }
|
78
|
+
expose :value, documentation: {
|
79
|
+
type: String, desc: 'Value of parameter', required: true }
|
80
|
+
end
|
81
|
+
|
82
|
+
class QueryInput < Grape::Entity
|
83
|
+
expose :elements, using: Entities::QueryInputElement, documentation: {
|
84
|
+
type: 'QueryInputElement',
|
85
|
+
desc: 'Set of configuration',
|
86
|
+
param_type: 'body',
|
87
|
+
is_array: true,
|
88
|
+
required: true
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
class QueryResult < Grape::Entity
|
93
|
+
expose :elements_size, documentation: { type: Integer, desc: 'Return input elements size' }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
75
97
|
def app
|
76
98
|
Class.new(Grape::API) do
|
77
99
|
format :json
|
@@ -98,7 +120,6 @@ describe 'API Models' do
|
|
98
120
|
|
99
121
|
desc 'This tests the enum values in params and documentation.', entity: Entities::EnumValues, params: Entities::EnumValues.documentation
|
100
122
|
get '/enum_description_in_entity' do
|
101
|
-
|
102
123
|
enum_value = OpenStruct.new gender: 'Male', number: 1
|
103
124
|
|
104
125
|
present enum_value, with: Entities::EnumValues
|
@@ -120,6 +141,14 @@ describe 'API Models' do
|
|
120
141
|
present first_level, with: Entities::FirstLevel
|
121
142
|
end
|
122
143
|
|
144
|
+
desc 'This tests diffrent entity for input and diffrent for output',
|
145
|
+
entity: [Entities::QueryResult, Entities::QueryInput],
|
146
|
+
params: Entities::QueryInput.documentation
|
147
|
+
get '/multiple_entities' do
|
148
|
+
result = OpenStruct.new(elements_size: params[:elements].size)
|
149
|
+
present result, with: Entities::QueryResult
|
150
|
+
end
|
151
|
+
|
123
152
|
add_swagger_documentation
|
124
153
|
end
|
125
154
|
end
|
@@ -147,6 +176,7 @@ describe 'API Models' do
|
|
147
176
|
{ 'path' => '/enum_description_in_entity.{format}', 'description' => 'Operations about enum_description_in_entities' },
|
148
177
|
{ 'path' => '/aliasedthing.{format}', 'description' => 'Operations about aliasedthings' },
|
149
178
|
{ 'path' => '/nesting.{format}', 'description' => 'Operations about nestings' },
|
179
|
+
{ 'path' => '/multiple_entities.{format}', 'description' => 'Operations about multiple_entities' },
|
150
180
|
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
151
181
|
]
|
152
182
|
end
|
@@ -226,7 +256,6 @@ describe 'API Models' do
|
|
226
256
|
],
|
227
257
|
'type' => 'EnumValues'
|
228
258
|
)
|
229
|
-
|
230
259
|
end
|
231
260
|
|
232
261
|
it 'includes referenced models in those with aliased references.' do
|
@@ -254,4 +283,11 @@ describe 'API Models' do
|
|
254
283
|
|
255
284
|
expect(result['models']).to include('FirstLevel', 'SecondLevel', 'ThirdLevel', 'FourthLevel')
|
256
285
|
end
|
286
|
+
|
287
|
+
it 'includes all entities while using multiple entities' do
|
288
|
+
get '/swagger_doc/multiple_entities'
|
289
|
+
result = JSON.parse(last_response.body)
|
290
|
+
|
291
|
+
expect(result['models']).to include('QueryInput', 'QueryInputElement', 'QueryResult')
|
292
|
+
end
|
257
293
|
end
|
data/spec/api_paths_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'simple api with prefix' do
|
4
|
-
|
5
4
|
before :all do
|
6
5
|
class ApiWithPrefix < Grape::API
|
7
6
|
prefix :api
|
@@ -16,7 +15,6 @@ describe 'simple api with prefix' do
|
|
16
15
|
mount ApiWithPrefix
|
17
16
|
add_swagger_documentation
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
|
22
20
|
def app
|
@@ -63,5 +61,4 @@ describe 'simple api with prefix' do
|
|
63
61
|
)
|
64
62
|
end
|
65
63
|
end
|
66
|
-
|
67
64
|
end
|
data/spec/api_root_spec.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Api with "path" versioning' do
|
4
|
+
let(:json_body) { JSON.parse(last_response.body) }
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
class ApiWithPathVersioning < Grape::API
|
8
|
+
format :json
|
9
|
+
version 'v1', using: :path
|
10
|
+
|
11
|
+
namespace :resources do
|
12
|
+
get
|
13
|
+
end
|
14
|
+
|
15
|
+
add_swagger_documentation api_version: 'v1'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def app
|
20
|
+
ApiWithPathVersioning
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'retrieves swagger-documentation on /swagger_doc that contains :resources api path' do
|
24
|
+
get '/v1/swagger_doc'
|
25
|
+
|
26
|
+
expect(json_body['apis']).to eq(
|
27
|
+
[
|
28
|
+
{ 'path' => '/resources.{format}', 'description' => 'Operations about resources' },
|
29
|
+
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
30
|
+
]
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Standalone namespace API' do
|
4
|
+
let(:json_body) { JSON.parse(last_response.body) }
|
5
|
+
|
6
|
+
describe 'with "path" versioning' do
|
7
|
+
before do
|
8
|
+
class StandaloneApiWithPathVersioning < Grape::API
|
9
|
+
format :json
|
10
|
+
version 'v1', using: :path
|
11
|
+
|
12
|
+
namespace :store do
|
13
|
+
get
|
14
|
+
# will be assigned to standalone the namespace below
|
15
|
+
namespace :orders do
|
16
|
+
get :order_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace 'store/orders', swagger: { nested: false } do
|
21
|
+
post :order_idx
|
22
|
+
namespace 'actions' do
|
23
|
+
get 'dummy'
|
24
|
+
end
|
25
|
+
namespace 'actions2', swagger: { nested: false } do
|
26
|
+
get 'dummy2'
|
27
|
+
namespace 'actions22' do
|
28
|
+
get 'dummy22'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
namespace 'store/:store_id/orders', swagger: { nested: false, name: 'specific-store-orders' } do
|
34
|
+
delete :order_id
|
35
|
+
end
|
36
|
+
|
37
|
+
add_swagger_documentation api_version: 'v1'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def app
|
42
|
+
StandaloneApiWithPathVersioning
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'retrieves swagger-documentation on /swagger_doc' do
|
46
|
+
before { get '/v1/swagger_doc' }
|
47
|
+
|
48
|
+
it 'that contains all api paths' do
|
49
|
+
expect(json_body['apis']).to eq(
|
50
|
+
[
|
51
|
+
{ 'path' => '/store.{format}', 'description' => 'Operations about stores' },
|
52
|
+
{ 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' },
|
53
|
+
{ 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' },
|
54
|
+
{ 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' },
|
55
|
+
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
56
|
+
]
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store' do
|
62
|
+
before { get '/v1/swagger_doc/store' }
|
63
|
+
it 'does not include standalone namespaces' do
|
64
|
+
apis = json_body['apis']
|
65
|
+
# shall include 1 route, GET on store
|
66
|
+
expect(apis.length).to eql(1)
|
67
|
+
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
72
|
+
before { get '/v1/swagger_doc/store_orders' }
|
73
|
+
it 'does not assign namespaces within standalone namespaces to the general resource' do
|
74
|
+
apis = json_body['apis']
|
75
|
+
# shall include 3 routes, get on store, get with order_id and get dummy on actions
|
76
|
+
expect(apis.length).to eql(3)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders_actions2' do
|
81
|
+
before { get '/v1/swagger_doc/store_orders_actions2' }
|
82
|
+
it 'does appear as standalone namespace within another standalone namespace' do
|
83
|
+
apis = json_body['apis']
|
84
|
+
# shall include 2 routes, get on dummy2 and get on dummy22
|
85
|
+
expect(apis.length).to eql(2)
|
86
|
+
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
87
|
+
expect(apis[1]['operations'][0]['method']).to eql('GET')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/specific-store-orders' do
|
92
|
+
before { get '/v1/swagger_doc/specific-store-orders' }
|
93
|
+
it 'does show the one route' do
|
94
|
+
apis = json_body['apis']
|
95
|
+
# shall include 1 routes, delete action
|
96
|
+
expect(apis.length).to eql(1)
|
97
|
+
expect(apis[0]['operations'][0]['method']).to eql('DELETE')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
102
|
+
before { get '/v1/swagger_doc/store_orders_actions2' }
|
103
|
+
it 'does work with standalone in standalone namespaces' do
|
104
|
+
apis = json_body['apis']
|
105
|
+
# shall include 2 routes, dummy2 and dummy22
|
106
|
+
expect(apis.length).to eql(2)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'with header versioning' do
|
112
|
+
before do
|
113
|
+
class StandaloneApiWithHeaderVersioning < Grape::API
|
114
|
+
format :json
|
115
|
+
version 'v1', using: :header, vendor: 'grape-swagger'
|
116
|
+
|
117
|
+
namespace :store do
|
118
|
+
get
|
119
|
+
# will be assigned to standalone the namespace below
|
120
|
+
namespace :orders do
|
121
|
+
get :order_id
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
namespace 'store/orders', swagger: { nested: false } do
|
126
|
+
post :order_idx
|
127
|
+
namespace 'actions' do
|
128
|
+
get 'dummy'
|
129
|
+
end
|
130
|
+
namespace 'actions2', swagger: { nested: false } do
|
131
|
+
get 'dummy2'
|
132
|
+
namespace 'actions22' do
|
133
|
+
get 'dummy22'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
namespace 'store/:store_id/orders', swagger: { nested: false, name: 'specific-store-orders' } do
|
139
|
+
delete :order_id
|
140
|
+
end
|
141
|
+
|
142
|
+
add_swagger_documentation api_version: 'v1'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def app
|
147
|
+
StandaloneApiWithHeaderVersioning
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'retrieves swagger-documentation on /swagger_doc' do
|
151
|
+
before { get 'swagger_doc' }
|
152
|
+
|
153
|
+
it 'that contains all api paths' do
|
154
|
+
expect(json_body['apis']).to eq(
|
155
|
+
[
|
156
|
+
{ 'path' => '/store.{format}', 'description' => 'Operations about stores' },
|
157
|
+
{ 'path' => '/store_orders.{format}', 'description' => 'Operations about store/orders' },
|
158
|
+
{ 'path' => '/store_orders_actions2.{format}', 'description' => 'Operations about store/orders/actions2s' },
|
159
|
+
{ 'path' => '/specific-store-orders.{format}', 'description' => 'Operations about store/:store_id/orders' },
|
160
|
+
{ 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' }
|
161
|
+
]
|
162
|
+
)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store' do
|
167
|
+
before { get '/swagger_doc/store' }
|
168
|
+
it 'does not include standalone namespaces' do
|
169
|
+
apis = json_body['apis']
|
170
|
+
# shall include 1 route, GET on store
|
171
|
+
expect(apis.length).to eql(1)
|
172
|
+
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
177
|
+
before { get '/swagger_doc/store_orders' }
|
178
|
+
it 'does not assign namespaces within standalone namespaces to the general resource' do
|
179
|
+
apis = json_body['apis']
|
180
|
+
# shall include 3 routes, get on store, get with order_id and get dummy on actions
|
181
|
+
expect(apis.length).to eql(3)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders_actions2' do
|
186
|
+
before { get '/swagger_doc/store_orders_actions2' }
|
187
|
+
it 'does appear as standalone namespace within another standalone namespace' do
|
188
|
+
apis = json_body['apis']
|
189
|
+
# shall include 2 routes, get on dummy2 and get on dummy22
|
190
|
+
expect(apis.length).to eql(2)
|
191
|
+
expect(apis[0]['operations'][0]['method']).to eql('GET')
|
192
|
+
expect(apis[1]['operations'][0]['method']).to eql('GET')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/specific-store-orders' do
|
197
|
+
before { get '/swagger_doc/specific-store-orders' }
|
198
|
+
it 'does show the one route' do
|
199
|
+
apis = json_body['apis']
|
200
|
+
# shall include 1 routes, delete action
|
201
|
+
expect(apis.length).to eql(1)
|
202
|
+
expect(apis[0]['operations'][0]['method']).to eql('DELETE')
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'retrieved namespace swagger-documentation on /swagger_doc/store_orders' do
|
207
|
+
before { get '/swagger_doc/store_orders_actions2' }
|
208
|
+
it 'does work with standalone in standalone namespaces' do
|
209
|
+
apis = json_body['apis']
|
210
|
+
# shall include 2 routes, dummy2 and dummy22
|
211
|
+
expect(apis.length).to eql(2)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Array Params' do
|
4
|
+
def app
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
format :json
|
7
|
+
|
8
|
+
params do
|
9
|
+
requires :a_array, type: Array do
|
10
|
+
requires :param_1, type: Integer
|
11
|
+
requires :param_2, type: String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
post :splines do
|
15
|
+
end
|
16
|
+
|
17
|
+
add_swagger_documentation
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
subject do
|
22
|
+
get '/swagger_doc/splines'
|
23
|
+
expect(last_response.status).to eq 200
|
24
|
+
body = JSON.parse last_response.body
|
25
|
+
body['apis'].first['operations'].first['parameters']
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gets array types' do
|
29
|
+
expect(subject).to eq [
|
30
|
+
{ 'paramType' => 'form', 'name' => 'a_array[][param_1]', 'description' => nil, 'type' => 'integer', 'required' => true, 'allowMultiple' => false, 'format' => 'int32' },
|
31
|
+
{ 'paramType' => 'form', 'name' => 'a_array[][param_2]', 'description' => nil, 'type' => 'string', 'required' => true, 'allowMultiple' => false }
|
32
|
+
]
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Float Params' do
|
4
|
+
def app
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
format :json
|
7
|
+
|
8
|
+
params do
|
9
|
+
requires :a_float, type: Float
|
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 'converts float types' do
|
26
|
+
expect(subject).to eq [
|
27
|
+
{ 'paramType' => 'form', 'name' => 'a_float', 'description' => nil, 'type' => 'float', 'required' => true, 'allowMultiple' => false }
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|