apipie-rails 1.3.0 → 1.4.1
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/.github/workflows/build.yml +4 -3
- data/.github/workflows/rubocop-challenger.yml +1 -3
- data/.github/workflows/rubocop.yml +1 -1
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +22 -99
- data/CHANGELOG.md +24 -0
- data/Gemfile +2 -3
- data/README.md +2088 -0
- data/apipie-rails.gemspec +8 -1
- data/app/views/apipie/apipies/_method_detail.erb +2 -0
- data/app/views/apipie/apipies/_params.html.erb +1 -0
- data/app/views/apipie/apipies/_params_plain.html.erb +1 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/lib/apipie/application.rb +1 -1
- data/lib/apipie/dsl_definition.rb +3 -3
- data/lib/apipie/error_description.rb +7 -5
- data/lib/apipie/extractor/recorder.rb +3 -3
- data/lib/apipie/extractor/writer.rb +7 -7
- data/lib/apipie/generator/swagger/method_description/response_service.rb +14 -1
- data/lib/apipie/generator/swagger/param_description/in.rb +1 -1
- data/lib/apipie/generator/swagger/type_extractor.rb +1 -1
- data/lib/apipie/generator/swagger/warning.rb +2 -2
- data/lib/apipie/helpers.rb +1 -1
- data/lib/apipie/param_description.rb +1 -1
- data/lib/apipie/response_description.rb +44 -14
- data/lib/apipie/response_description_adapter.rb +1 -1
- data/lib/apipie/routes_formatter.rb +2 -2
- data/lib/apipie/version.rb +1 -1
- data/lib/tasks/apipie.rake +4 -4
- data/rel-eng/gem_release.ipynb +5 -5
- data/spec/controllers/api/v1/architectures_controller_spec.rb +3 -3
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +1 -1
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +2 -2
- data/spec/controllers/included_param_group_controller_spec.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +65 -64
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +1 -1
- data/spec/dummy/app/controllers/extending_concern.rb +7 -7
- data/spec/dummy/app/controllers/pets_controller.rb +5 -5
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +2 -2
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +16 -16
- data/spec/dummy/app/controllers/sample_controller.rb +31 -31
- data/spec/dummy/app/controllers/twitter_example_controller.rb +3 -3
- data/spec/lib/apipie/apipies_controller_spec.rb +1 -1
- data/spec/lib/apipie/application_spec.rb +2 -2
- data/spec/lib/apipie/extractor/writer_spec.rb +8 -8
- data/spec/lib/apipie/file_handler_spec.rb +1 -1
- data/spec/lib/apipie/generator/swagger/method_description/response_service_spec.rb +62 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +2 -2
- data/spec/lib/apipie/method_description_spec.rb +2 -2
- data/spec/lib/apipie/param_description_spec.rb +48 -48
- data/spec/lib/apipie/param_group_spec.rb +4 -4
- data/spec/lib/apipie/resource_description_spec.rb +2 -2
- data/spec/lib/apipie/response_description/response_object_spec.rb +22 -0
- data/spec/lib/apipie/response_description_spec.rb +56 -0
- data/spec/lib/apipie/validator_spec.rb +12 -12
- data/spec/lib/swagger/swagger_dsl_spec.rb +39 -39
- data/spec/test_engine/memes_controller_spec.rb +1 -1
- metadata +147 -7
- data/README.rst +0 -1968
@@ -28,7 +28,7 @@ describe UsersController do
|
|
28
28
|
Apipie.get_resource_description(UsersController, Apipie.configuration.default_version)
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "contains all resource methods" do
|
32
32
|
methods = subject._methods
|
33
33
|
expect(methods.keys).to include(:show)
|
34
34
|
expect(methods.keys).to include(:create_route)
|
@@ -40,7 +40,7 @@ describe UsersController do
|
|
40
40
|
expect(methods.keys).to include(:multiple_required_params)
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "contains info about resource" do
|
44
44
|
expect(subject._short_description).to eq('Site members')
|
45
45
|
expect(subject._id).to eq('users')
|
46
46
|
expect(subject._path).to eq('/users')
|
@@ -49,7 +49,7 @@ describe UsersController do
|
|
49
49
|
expect(subject._formats).to eq(['json'])
|
50
50
|
end
|
51
51
|
|
52
|
-
it "
|
52
|
+
it "contains params defined on resource level" do
|
53
53
|
expect(subject._params_args.count).to eq(2)
|
54
54
|
name, type, options = subject._params_args.first
|
55
55
|
expect(name).to eq(:id)
|
@@ -67,12 +67,12 @@ describe UsersController do
|
|
67
67
|
Apipie.configuration.validate_presence = true
|
68
68
|
end
|
69
69
|
|
70
|
-
it "
|
70
|
+
it "replies to valid request" do
|
71
71
|
get :show, :params => { :id => '5', :session => "secret_hash" }
|
72
72
|
assert_response :success
|
73
73
|
end
|
74
74
|
|
75
|
-
it "
|
75
|
+
it "passes if required parameter is missing" do
|
76
76
|
expect { get :show, :params => { :id => 5 } }.not_to raise_error
|
77
77
|
end
|
78
78
|
|
@@ -93,20 +93,20 @@ describe UsersController do
|
|
93
93
|
Apipie.configuration.validate_key = false
|
94
94
|
end
|
95
95
|
|
96
|
-
it "
|
96
|
+
it "replies to valid request" do
|
97
97
|
expect { get :show, :params => { :id => 5, :session => "secret_hash" }}.not_to raise_error
|
98
98
|
assert_response :success
|
99
99
|
end
|
100
100
|
|
101
|
-
it "
|
101
|
+
it "fails if required parameter is missing" do
|
102
102
|
expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
103
103
|
end
|
104
104
|
|
105
|
-
it "
|
105
|
+
it "fails if multiple required parameters are missing" do
|
106
106
|
expect { get :multiple_required_params }.to raise_error(Apipie::ParamMultipleMissing, /required_param1.*\n.*required_param2|required_param2.*\n.*required_parameter1/)
|
107
107
|
end
|
108
108
|
|
109
|
-
it "
|
109
|
+
it "passes if required parameter has wrong type" do
|
110
110
|
expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
|
111
111
|
expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
|
112
112
|
end
|
@@ -120,12 +120,12 @@ describe UsersController do
|
|
120
120
|
Apipie.configuration.validate_key = true
|
121
121
|
end
|
122
122
|
|
123
|
-
it "
|
123
|
+
it "replies to valid request" do
|
124
124
|
expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
|
125
125
|
assert_response :success
|
126
126
|
end
|
127
127
|
|
128
|
-
it "
|
128
|
+
it "fails if extra parameter is passed in" do
|
129
129
|
expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
|
130
130
|
end
|
131
131
|
end
|
@@ -138,12 +138,12 @@ describe UsersController do
|
|
138
138
|
Apipie.configuration.action_on_non_validated_keys = :skip
|
139
139
|
end
|
140
140
|
|
141
|
-
it "
|
141
|
+
it "replies to valid request" do
|
142
142
|
expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
|
143
143
|
assert_response :success
|
144
144
|
end
|
145
145
|
|
146
|
-
it "
|
146
|
+
it "deletes the param and not fail if an extra parameter is passed." do
|
147
147
|
expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.not_to raise_error
|
148
148
|
expect(controller.params.as_json).to eq({"session"=>"secret_hash", "id"=>"5", "controller"=>"users", "action"=>"show"})
|
149
149
|
end
|
@@ -160,41 +160,42 @@ describe UsersController do
|
|
160
160
|
Apipie.configuration.validate_key = false
|
161
161
|
end
|
162
162
|
|
163
|
-
it "
|
163
|
+
it "replies to valid request" do
|
164
164
|
get :show, :params => { :id => '5', :session => "secret_hash" }
|
165
165
|
assert_response :success
|
166
166
|
end
|
167
167
|
|
168
|
-
it "
|
169
|
-
expect
|
168
|
+
it "works with nil value for a required hash param" do
|
169
|
+
expect do
|
170
170
|
get :show, :params => { :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil} }
|
171
|
-
|
171
|
+
end.to raise_error(Apipie::ParamInvalid, /dummy_hash/)
|
172
172
|
assert_response :success
|
173
173
|
end
|
174
174
|
|
175
|
-
it "
|
175
|
+
it "fails if required parameter is missing" do
|
176
176
|
expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
177
177
|
end
|
178
178
|
|
179
|
-
|
180
|
-
|
179
|
+
# old-style error rather than ParamInvalid
|
180
|
+
it "works with custom Type validator" do
|
181
|
+
expect do
|
181
182
|
get :show,
|
182
183
|
:params => { :id => "not a number", :session => "secret_hash" }
|
183
|
-
|
184
|
+
end.to raise_error(Apipie::ParamError, /id/)
|
184
185
|
end
|
185
186
|
|
186
|
-
it "
|
187
|
+
it "works with Regexp validator" do
|
187
188
|
get :show, :params => { :id => 5, :session => "secret_hash", :regexp_param => "24 years" }
|
188
189
|
assert_response :success
|
189
190
|
|
190
|
-
expect
|
191
|
+
expect do
|
191
192
|
get :show, :params => { :id => 5,
|
192
193
|
:session => "secret_hash",
|
193
194
|
:regexp_param => "ten years" }
|
194
|
-
|
195
|
+
end.to raise_error(Apipie::ParamInvalid, /regexp_param/)
|
195
196
|
end
|
196
197
|
|
197
|
-
it "
|
198
|
+
it "works with Array validator" do
|
198
199
|
get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "one" }
|
199
200
|
assert_response :success
|
200
201
|
get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "two" }
|
@@ -202,28 +203,28 @@ describe UsersController do
|
|
202
203
|
get :show, :params => { :id => 5, :session => "secret_hash", :array_param => '1' }
|
203
204
|
assert_response :success
|
204
205
|
|
205
|
-
expect
|
206
|
+
expect do
|
206
207
|
get :show, :params => { :id => 5,
|
207
208
|
:session => "secret_hash",
|
208
209
|
:array_param => "blabla" }
|
209
|
-
|
210
|
+
end.to raise_error(Apipie::ParamInvalid, /array_param/)
|
210
211
|
|
211
|
-
expect
|
212
|
+
expect do
|
212
213
|
get :show, :params => {
|
213
214
|
:id => 5,
|
214
215
|
:session => "secret_hash",
|
215
216
|
:array_param => 3 }
|
216
|
-
|
217
|
+
end.to raise_error(Apipie::ParamInvalid, /array_param/)
|
217
218
|
end
|
218
219
|
|
219
|
-
it "
|
220
|
-
expect
|
220
|
+
it "works with Proc validator" do
|
221
|
+
expect do
|
221
222
|
get :show,
|
222
223
|
:params => {
|
223
224
|
:id => 5,
|
224
225
|
:session => "secret_hash",
|
225
226
|
:proc_param => "asdgsag" }
|
226
|
-
|
227
|
+
end.to raise_error(Apipie::ParamInvalid, /proc_param/)
|
227
228
|
|
228
229
|
get :show,
|
229
230
|
:params => {
|
@@ -233,7 +234,7 @@ describe UsersController do
|
|
233
234
|
assert_response :success
|
234
235
|
end
|
235
236
|
|
236
|
-
it "
|
237
|
+
it "works with Hash validator" do
|
237
238
|
post :create, params: { :user => { :name => "root", :pass => "12345", :membership => "standard" } }
|
238
239
|
assert_response :success
|
239
240
|
|
@@ -247,28 +248,28 @@ describe UsersController do
|
|
247
248
|
hash_params[1].name == :pass
|
248
249
|
hash_params[2].name == :membership
|
249
250
|
|
250
|
-
expect
|
251
|
+
expect do
|
251
252
|
post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } }
|
252
|
-
|
253
|
+
end.to raise_error(Apipie::ParamInvalid, /membership/)
|
253
254
|
|
254
255
|
# Should include both pass and name
|
255
|
-
expect
|
256
|
+
expect do
|
256
257
|
post :create, :params => { :user => { :membership => "standard" } }
|
257
|
-
|
258
|
+
end.to raise_error(Apipie::ParamMultipleMissing, /pass.*\n.*name|name.*\n.*pass/)
|
258
259
|
|
259
|
-
expect
|
260
|
+
expect do
|
260
261
|
post :create, :params => { :user => { :name => "root" } }
|
261
|
-
|
262
|
+
end.to raise_error(Apipie::ParamMissing, /pass/)
|
262
263
|
|
263
|
-
expect
|
264
|
+
expect do
|
264
265
|
post :create, :params => { :user => "a string is not a hash" }
|
265
|
-
|
266
|
+
end.to raise_error(Apipie::ParamInvalid, /user/)
|
266
267
|
|
267
268
|
post :create, :params => { :user => { :name => "root", :pass => "pwd" } }
|
268
269
|
assert_response :success
|
269
270
|
end
|
270
271
|
|
271
|
-
it "
|
272
|
+
it "supports Hash validator without specifying keys" do
|
272
273
|
params = Apipie[UsersController, :create].to_json[:params]
|
273
274
|
expect(params).to include(:name => "facts",
|
274
275
|
:full_name => "facts",
|
@@ -284,7 +285,7 @@ describe UsersController do
|
|
284
285
|
:validations => [])
|
285
286
|
end
|
286
287
|
|
287
|
-
it "
|
288
|
+
it "allows nil when allow_nil is set to true" do
|
288
289
|
post :create,
|
289
290
|
:params => {
|
290
291
|
:user => {
|
@@ -297,7 +298,7 @@ describe UsersController do
|
|
297
298
|
assert_response :success
|
298
299
|
end
|
299
300
|
|
300
|
-
it "
|
301
|
+
it "allows blank when allow_blank is set to true" do
|
301
302
|
post :create,
|
302
303
|
:params => {
|
303
304
|
:user => {
|
@@ -313,7 +314,7 @@ describe UsersController do
|
|
313
314
|
describe "nested elements" do
|
314
315
|
|
315
316
|
context "with valid input" do
|
316
|
-
it "
|
317
|
+
it "succeeds" do
|
317
318
|
put :update,
|
318
319
|
:params => {
|
319
320
|
:id => 5,
|
@@ -335,8 +336,8 @@ describe UsersController do
|
|
335
336
|
end
|
336
337
|
end
|
337
338
|
context "with bad input" do
|
338
|
-
it "
|
339
|
-
expect
|
339
|
+
it "raises an error" do
|
340
|
+
expect do
|
340
341
|
put :update,
|
341
342
|
:params => {
|
342
343
|
:id => 5,
|
@@ -353,10 +354,10 @@ describe UsersController do
|
|
353
354
|
}
|
354
355
|
]
|
355
356
|
}
|
356
|
-
|
357
|
+
end.to raise_error(Apipie::ParamInvalid)
|
357
358
|
end
|
358
359
|
end
|
359
|
-
it "
|
360
|
+
it "works with empty array" do
|
360
361
|
put :update,
|
361
362
|
:params => {
|
362
363
|
:id => 5,
|
@@ -407,7 +408,7 @@ describe UsersController do
|
|
407
408
|
|
408
409
|
describe "method description" do
|
409
410
|
|
410
|
-
it "
|
411
|
+
it "contains basic info about method" do
|
411
412
|
a = Apipie[UsersController, :create]
|
412
413
|
expect(a.apis.count).to eq(1)
|
413
414
|
expect(a.formats).to eq(['json'])
|
@@ -430,8 +431,8 @@ describe UsersController do
|
|
430
431
|
expect(b.full_description.length).to be > 400
|
431
432
|
end
|
432
433
|
|
433
|
-
context "
|
434
|
-
it "
|
434
|
+
context "Using routes.rb" do
|
435
|
+
it "contains basic info about method" do
|
435
436
|
a = Apipie[UsersController, :create_route]
|
436
437
|
expect(a.apis.count).to eq(1)
|
437
438
|
expect(a.formats).to eq(['json'])
|
@@ -446,7 +447,7 @@ describe UsersController do
|
|
446
447
|
context "contain :see option" do
|
447
448
|
|
448
449
|
context "the key is valid" do
|
449
|
-
it "
|
450
|
+
it "contains reference to another method" do
|
450
451
|
api = Apipie[UsersController, :see_another]
|
451
452
|
expect(api.show).to be false
|
452
453
|
see = api.see.first
|
@@ -464,18 +465,18 @@ describe UsersController do
|
|
464
465
|
end
|
465
466
|
|
466
467
|
context "the key is not valid" do
|
467
|
-
it "
|
468
|
+
it "raises exception" do
|
468
469
|
api = Apipie[UsersController, :see_another]
|
469
470
|
api.instance_variable_set :@see, [Apipie::SeeDescription.new(['doesnot#exist'])]
|
470
|
-
expect
|
471
|
+
expect do
|
471
472
|
api.see.first.see_url
|
472
|
-
|
473
|
+
end.to raise_error(ArgumentError, /does not exist/)
|
473
474
|
api.instance_variable_set :@see, []
|
474
475
|
end
|
475
476
|
end
|
476
477
|
end
|
477
478
|
|
478
|
-
it "
|
479
|
+
it "contains possible errors description" do
|
479
480
|
a = Apipie.get_method_description(UsersController, :show)
|
480
481
|
|
481
482
|
expect(a.errors[0].code).to eq(500)
|
@@ -486,7 +487,7 @@ describe UsersController do
|
|
486
487
|
expect(a.errors[2].description).to eq("Not Found")
|
487
488
|
end
|
488
489
|
|
489
|
-
it '
|
490
|
+
it 'recognizes Rack symbols as error codes' do
|
490
491
|
a = Apipie.get_method_description(UsersController, :create)
|
491
492
|
|
492
493
|
error = a.errors.find { |e| e.code == 422 }
|
@@ -494,7 +495,7 @@ describe UsersController do
|
|
494
495
|
expect(error.description).to include("Unprocessable Entity")
|
495
496
|
end
|
496
497
|
|
497
|
-
it "
|
498
|
+
it "contains all params description" do
|
498
499
|
a = Apipie.get_method_description(UsersController, :show)
|
499
500
|
expect(a.params.count).to eq(12)
|
500
501
|
expect(a.instance_variable_get('@params_ordered').count).to eq(10)
|
@@ -564,7 +565,7 @@ describe UsersController do
|
|
564
565
|
end
|
565
566
|
end
|
566
567
|
|
567
|
-
it "
|
568
|
+
it "contains all api method description" do
|
568
569
|
method_description = Apipie[UsersController, :two_urls]
|
569
570
|
expect(method_description.class).to be(Apipie::MethodDescription)
|
570
571
|
expect(method_description.apis.count).to eq(2)
|
@@ -579,7 +580,7 @@ describe UsersController do
|
|
579
580
|
expect(a2.http_method).to eq('GET')
|
580
581
|
end
|
581
582
|
|
582
|
-
it "
|
583
|
+
it "is described by valid json" do
|
583
584
|
json = Apipie[UsersController, :two_urls].to_json
|
584
585
|
expected_hash = {
|
585
586
|
:errors => [{:code=>404, :description=>"Missing", :metadata => {:some => "metadata"}},
|
@@ -672,7 +673,7 @@ describe UsersController do
|
|
672
673
|
|
673
674
|
describe "examples" do
|
674
675
|
|
675
|
-
it "
|
676
|
+
it "is able to load examples from yml file" do
|
676
677
|
expect(Apipie.get_method_description(UsersController, :show).examples).to eq [<<EOS1, <<EOS2].map(&:chomp)
|
677
678
|
GET /users/14?verbose=true
|
678
679
|
200
|
@@ -686,7 +687,7 @@ EOS2
|
|
686
687
|
end
|
687
688
|
|
688
689
|
describe "document" do
|
689
|
-
it "
|
690
|
+
it "is able to load document from markup file" do
|
690
691
|
expect(Apipie.get_method_description(UsersController, :desc_from_file).full_description).to include("description from document")
|
691
692
|
end
|
692
693
|
end
|
@@ -694,7 +695,7 @@ EOS2
|
|
694
695
|
|
695
696
|
describe "param description" do
|
696
697
|
|
697
|
-
it "
|
698
|
+
it "contains all specified information" do
|
698
699
|
a = Apipie.get_method_description(UsersController, :show)
|
699
700
|
|
700
701
|
param = a.params[:session]
|
@@ -2,7 +2,7 @@ module Api
|
|
2
2
|
module V2
|
3
3
|
class EmptyMiddleController < V2::BaseController
|
4
4
|
# This is an empty controller, used to test cases where controllers
|
5
|
-
# may inherit from a middle
|
5
|
+
# may inherit from a middle controller that does not define a resource_description,
|
6
6
|
# but the middle controller's parent does.
|
7
7
|
|
8
8
|
def inconsequential_method
|
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module ExtendingConcern
|
2
|
+
extend Apipie::DSL::Concern
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
meta metadata: 'data'
|
4
|
+
update_api(:create) do
|
5
|
+
param :user, Hash do
|
6
|
+
param :from_concern, String, :desc => 'param from concern', :allow_nil => false
|
9
7
|
end
|
8
|
+
meta metadata: 'data'
|
10
9
|
end
|
10
|
+
end
|
@@ -63,7 +63,7 @@ class PetsController < ApplicationController
|
|
63
63
|
# mixing request/response and response-only parameters
|
64
64
|
#
|
65
65
|
# the param_group :pet_with_id has several parameters which are
|
66
|
-
# not
|
66
|
+
# not expected in the request, but would show up in the response
|
67
67
|
# and vice versa
|
68
68
|
#-----------------------------------------------------------
|
69
69
|
def_param_group :pet_with_id do
|
@@ -364,8 +364,8 @@ class PetsController < ApplicationController
|
|
364
364
|
result = {
|
365
365
|
a_number: 3,
|
366
366
|
array_of_objects: [
|
367
|
-
|
368
|
-
|
367
|
+
{number1: 1, number2: 2},
|
368
|
+
{number1: 10, number2: 20}
|
369
369
|
]
|
370
370
|
}
|
371
371
|
render :json => result
|
@@ -387,8 +387,8 @@ class PetsController < ApplicationController
|
|
387
387
|
result = {
|
388
388
|
a_number: 3,
|
389
389
|
array_of_objects: [
|
390
|
-
|
391
|
-
|
390
|
+
{number1: 1, number2: 2},
|
391
|
+
{number1: 10, number2: "this should have been a number"}
|
392
392
|
]
|
393
393
|
}
|
394
394
|
render :json => result
|
@@ -22,11 +22,11 @@ class SelfDocumentingView
|
|
22
22
|
# self.describe_own_properties (a class method) generates the meta-data
|
23
23
|
# (i.e., the type description) for the subclass.
|
24
24
|
def self.describe_own_properties
|
25
|
-
(self.instance_methods - self.class.instance_methods).map
|
25
|
+
(self.instance_methods - self.class.instance_methods).map do |m|
|
26
26
|
if matchdata = /^v_(\w+)__(\w+)$/.match(m)
|
27
27
|
Apipie::prop(matchdata[1], matchdata[2])
|
28
28
|
end
|
29
|
-
|
29
|
+
end.compact
|
30
30
|
end
|
31
31
|
|
32
32
|
# to_json (an instance method) generates the actual view
|
@@ -13,9 +13,9 @@
|
|
13
13
|
class Pet
|
14
14
|
def self.describe_own_properties
|
15
15
|
[
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
17
|
+
Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
|
18
|
+
Apipie::additional_properties(false)
|
19
19
|
]
|
20
20
|
end
|
21
21
|
end
|
@@ -26,14 +26,14 @@ end
|
|
26
26
|
class PetWithMeasurements
|
27
27
|
def self.describe_own_properties
|
28
28
|
[
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
30
|
+
Apipie::prop('animal_type', 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
|
31
|
+
Apipie::prop(:pet_measurements, 'object', {}, [
|
32
|
+
Apipie::prop(:weight, 'number', {:description => "Weight in pounds" }),
|
33
|
+
Apipie::prop(:height, 'number', {:description => "Height in inches" }),
|
34
|
+
Apipie::prop(:num_legs, 'number', {:description => "Number of legs", :required => false }),
|
35
|
+
Apipie::additional_properties(false)
|
36
|
+
])
|
37
37
|
]
|
38
38
|
end
|
39
39
|
end
|
@@ -44,11 +44,11 @@ end
|
|
44
44
|
class PetWithManyMeasurements
|
45
45
|
def self.describe_own_properties
|
46
46
|
[
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
48
|
+
Apipie::prop(:many_pet_measurements, 'object', {is_array: true}, [
|
49
|
+
Apipie::prop(:weight, 'number', {:description => "Weight in pounds" }),
|
50
|
+
Apipie::prop(:height, 'number', {:description => "Height in inches" }),
|
51
|
+
])
|
52
52
|
]
|
53
53
|
end
|
54
54
|
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module SampleController
|
2
|
+
extend Apipie::DSL::Concern
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
api!
|
5
|
+
def index
|
6
|
+
render :plain => "OK #{params.inspect}"
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
api :GET, '/:resource_id/:id'
|
10
|
+
param :id, String
|
11
|
+
def show
|
12
|
+
render :plain => "OK #{params.inspect}"
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
def_param_group :concern do
|
16
|
+
param :concern, Hash, :required => true, :action_aware => true do
|
17
|
+
param :name, String, "Name of a :concern"
|
18
|
+
param :concern_type, String
|
20
19
|
end
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
api :POST, '/:resource_id', "Create a :concern"
|
23
|
+
param_group :concern
|
24
|
+
def create
|
25
|
+
render :plain => "OK #{params.inspect}"
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
api :PUT, '/:resource_id/:id'
|
29
|
+
param :id, String
|
30
|
+
param_group :concern
|
31
|
+
def update
|
32
|
+
render :plain => "OK #{params.inspect}"
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
35
|
+
api :GET, '/:resource_id/:custom_subst'
|
36
|
+
def custom
|
37
|
+
render :plain => "OK #{params.inspect}"
|
39
38
|
end
|
39
|
+
end
|
@@ -10,7 +10,7 @@ class TwitterExampleController < ApplicationController
|
|
10
10
|
api :GET, '/twitter_example/lookup', 'Return up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two.'
|
11
11
|
param :screen_name, String, :desc => 'A comma separated list of screen names, up to 100 are allowed in a single request. You are strongly encouraged to use a POST for larger (up to 100 screen names) requests.'
|
12
12
|
param :user_id, Integer, :desc => 'A comma separated list of user IDs, up to 100 are allowed in a single request. You are strongly encouraged to use a POST for larger requests.'
|
13
|
-
param :include_entities, String, :desc => 'When set to either <code>true</code>, <code>t</code> or <code>1</code>, each tweet will include a node called "entities,". This node offers a variety of metadata about the tweet in a
|
13
|
+
param :include_entities, String, :desc => 'When set to either <code>true</code>, <code>t</code> or <code>1</code>, each tweet will include a node called "entities,". This node offers a variety of metadata about the tweet in a discrete structure, including: user_mentions, urls, and hashtags. While entities are opt-in on timelines at present, they will be made a default component of output in the future. See Tweet Entities for more detail on entities.'
|
14
14
|
|
15
15
|
description <<-EOS
|
16
16
|
Return up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two. The author's most recent status (if the authenticating user has permission) will be returned inline.
|
@@ -53,8 +53,8 @@ class TwitterExampleController < ApplicationController
|
|
53
53
|
api :GET, '/twitter_example/search', 'Runs a search for users similar to Find People button on Twitter.com.'
|
54
54
|
param :q, String, :desc => 'The search query to run against people search.', :required => true
|
55
55
|
param :page, Integer, :desc => 'Specifies the page of results to retrieve.'
|
56
|
-
param :per_page, Integer, :desc => 'The number of people to retrieve.
|
57
|
-
param :include_entities, String, :desc => 'When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a variety of metadata about the tweet in a
|
56
|
+
param :per_page, Integer, :desc => 'The number of people to retrieve. Maximum of 20 allowed per page.'
|
57
|
+
param :include_entities, String, :desc => 'When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a variety of metadata about the tweet in a discrete structure, including: user_mentions, urls, and hashtags. While entities are opt-in on timelines at present, they will be made a default component of output in the future. See Tweet Entities for more detail on entities.'
|
58
58
|
description <<-EOS
|
59
59
|
Runs a search for users similar to Find People button on Twitter.com. The results returned by people search on Twitter.com are the same as those returned by this API request. Note that unlike GET search, this method does not support any operators.
|
60
60
|
|
@@ -188,7 +188,7 @@ describe Apipie::ApipiesController, type: :controller do
|
|
188
188
|
|
189
189
|
|
190
190
|
describe "authenticate user" do
|
191
|
-
it "authenticate user if an authentication method is
|
191
|
+
it "authenticate user if an authentication method is set" do
|
192
192
|
test = false
|
193
193
|
Apipie.configuration.authenticate = Proc.new do
|
194
194
|
test = true
|
@@ -8,7 +8,7 @@ describe Apipie::Application do
|
|
8
8
|
File.join(Rails.root, "lib", "**","*.rb")]
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "supports receiving array as parameter" do
|
12
12
|
expect { Apipie.api_controllers_paths}.
|
13
13
|
not_to raise_error
|
14
14
|
end
|
@@ -33,7 +33,7 @@ describe Apipie::Application do
|
|
33
33
|
context "with an undefined base url" do
|
34
34
|
let(:base_url) { nil }
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "does not raise an error" do
|
37
37
|
expect { method_call }.not_to raise_error
|
38
38
|
end
|
39
39
|
end
|