apipie-rails 0.3.6 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +67 -0
  3. data/.github/workflows/rubocop-challenger.yml +28 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +37 -0
  6. data/.rubocop_todo.yml +1991 -0
  7. data/CHANGELOG.md +246 -2
  8. data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
  9. data/README.rst +646 -25
  10. data/Rakefile +0 -5
  11. data/apipie-rails.gemspec +14 -9
  12. data/app/controllers/apipie/apipies_controller.rb +51 -20
  13. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
  14. data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
  15. data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
  16. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
  17. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
  18. data/app/views/apipie/apipies/_method_detail.erb +21 -0
  19. data/app/views/apipie/apipies/_params.html.erb +4 -2
  20. data/app/views/apipie/apipies/index.html.erb +5 -1
  21. data/app/views/apipie/apipies/resource.html.erb +3 -0
  22. data/app/views/layouts/apipie/apipie.html.erb +1 -1
  23. data/config/locales/en.yml +1 -0
  24. data/config/locales/fr.yml +31 -0
  25. data/config/locales/it.yml +31 -0
  26. data/config/locales/ja.yml +31 -0
  27. data/config/locales/ko.yml +31 -0
  28. data/config/locales/pt-BR.yml +1 -1
  29. data/gemfiles/Gemfile.rails50 +10 -0
  30. data/gemfiles/Gemfile.rails51 +10 -0
  31. data/gemfiles/Gemfile.rails52 +10 -0
  32. data/gemfiles/Gemfile.rails60 +17 -0
  33. data/gemfiles/Gemfile.rails61 +17 -0
  34. data/gemfiles/Gemfile.rails70 +17 -0
  35. data/lib/apipie/apipie_module.rb +22 -4
  36. data/lib/apipie/application.rb +54 -25
  37. data/lib/apipie/configuration.rb +26 -4
  38. data/lib/apipie/core_ext/route.rb +9 -0
  39. data/lib/apipie/dsl_definition.rb +168 -16
  40. data/lib/apipie/error_description.rb +9 -2
  41. data/lib/apipie/errors.rb +34 -0
  42. data/lib/apipie/extractor/collector.rb +4 -0
  43. data/lib/apipie/extractor/recorder.rb +14 -12
  44. data/lib/apipie/extractor/writer.rb +86 -58
  45. data/lib/apipie/extractor.rb +5 -5
  46. data/lib/apipie/generator/generator.rb +2 -0
  47. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  48. data/lib/apipie/generator/swagger/type.rb +16 -0
  49. data/lib/apipie/generator/swagger/type_extractor.rb +70 -0
  50. data/lib/apipie/generator/swagger/warning.rb +77 -0
  51. data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
  52. data/lib/apipie/markup.rb +14 -11
  53. data/lib/apipie/method_description/api.rb +12 -0
  54. data/lib/apipie/method_description/apis_service.rb +82 -0
  55. data/lib/apipie/method_description.rb +51 -49
  56. data/lib/apipie/param_description.rb +63 -5
  57. data/lib/apipie/resource_description.rb +11 -4
  58. data/lib/apipie/response_description.rb +131 -0
  59. data/lib/apipie/response_description_adapter.rb +200 -0
  60. data/lib/apipie/routes_formatter.rb +1 -1
  61. data/lib/apipie/rspec/response_validation_helper.rb +194 -0
  62. data/lib/apipie/static_dispatcher.rb +5 -2
  63. data/lib/apipie/swagger_generator.rb +717 -0
  64. data/lib/apipie/tag_list_description.rb +11 -0
  65. data/lib/apipie/validator.rb +83 -9
  66. data/lib/apipie/version.rb +1 -1
  67. data/lib/apipie-rails.rb +15 -4
  68. data/lib/generators/apipie/install/install_generator.rb +1 -1
  69. data/lib/generators/apipie/views_generator.rb +1 -1
  70. data/lib/tasks/apipie.rake +115 -15
  71. data/rel-eng/gem_release.ipynb +398 -0
  72. data/spec/controllers/apipies_controller_spec.rb +79 -14
  73. data/spec/controllers/concerns_controller_spec.rb +2 -2
  74. data/spec/controllers/extended_controller_spec.rb +14 -0
  75. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  76. data/spec/controllers/memes_controller_spec.rb +10 -0
  77. data/spec/controllers/users_controller_spec.rb +139 -76
  78. data/spec/dummy/Rakefile +1 -1
  79. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  80. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  81. data/spec/dummy/app/controllers/extended_controller.rb +14 -0
  82. data/spec/dummy/app/controllers/extending_concern.rb +10 -0
  83. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  84. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  85. data/spec/dummy/app/controllers/pets_controller.rb +408 -0
  86. data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
  87. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
  88. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +5 -7
  89. data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
  90. data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
  91. data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
  92. data/spec/dummy/app/controllers/users_controller.rb +26 -12
  93. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  94. data/spec/dummy/components/test_engine/Gemfile +6 -0
  95. data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
  96. data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
  97. data/spec/dummy/components/test_engine/config/routes.rb +3 -0
  98. data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
  99. data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
  100. data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
  101. data/spec/dummy/config/application.rb +6 -4
  102. data/spec/dummy/config/boot.rb +2 -2
  103. data/spec/dummy/config/environment.rb +1 -1
  104. data/spec/dummy/config/environments/development.rb +3 -3
  105. data/spec/dummy/config/environments/production.rb +3 -3
  106. data/spec/dummy/config/environments/test.rb +3 -5
  107. data/spec/dummy/config/initializers/apipie.rb +5 -3
  108. data/spec/dummy/config/routes.rb +25 -1
  109. data/spec/dummy/config.ru +1 -1
  110. data/spec/dummy/script/rails +2 -2
  111. data/spec/lib/application_spec.rb +1 -1
  112. data/spec/lib/extractor/writer_spec.rb +37 -7
  113. data/spec/lib/file_handler_spec.rb +25 -0
  114. data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
  115. data/spec/lib/generator/swagger/warning_spec.rb +51 -0
  116. data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
  117. data/spec/lib/method_description/apis_service_spec.rb +60 -0
  118. data/spec/lib/method_description_spec.rb +34 -0
  119. data/spec/lib/param_description_spec.rb +90 -4
  120. data/spec/lib/rake_spec.rb +2 -4
  121. data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
  122. data/spec/lib/swagger/rake_swagger_spec.rb +154 -0
  123. data/spec/lib/swagger/response_validation_spec.rb +104 -0
  124. data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
  125. data/spec/lib/validator_spec.rb +59 -1
  126. data/spec/lib/validators/array_validator_spec.rb +28 -8
  127. data/spec/spec_helper.rb +49 -3
  128. data/spec/support/custom_bool_validator.rb +17 -0
  129. metadata +104 -99
  130. data/.travis.yml +0 -12
  131. data/Gemfile +0 -7
  132. data/Gemfile.rails32 +0 -6
  133. data/Gemfile.rails40 +0 -5
  134. data/Gemfile.rails41 +0 -5
  135. data/Gemfile.rails42 +0 -5
  136. data/lib/apipie/client/generator.rb +0 -135
@@ -51,7 +51,7 @@ describe UsersController do
51
51
  expect(subject._params_args.count).to eq(2)
52
52
  name, type, options = subject._params_args.first
53
53
  expect(name).to eq(:id)
54
- expect(type).to eq(Fixnum)
54
+ expect(type).to eq(Integer)
55
55
  expect(options).to eq({:required=>false, :desc=>"User ID"})
56
56
  end
57
57
  end
@@ -66,12 +66,12 @@ describe UsersController do
66
66
  end
67
67
 
68
68
  it "should reply to valid request" do
69
- get :show, :id => '5', :session => "secret_hash"
69
+ get :show, :params => { :id => '5', :session => "secret_hash" }
70
70
  assert_response :success
71
71
  end
72
72
 
73
73
  it "should pass if required parameter is missing" do
74
- expect { get :show, :id => 5 }.not_to raise_error
74
+ expect { get :show, :params => { :id => 5 } }.not_to raise_error
75
75
  end
76
76
 
77
77
  end
@@ -92,17 +92,17 @@ describe UsersController do
92
92
  end
93
93
 
94
94
  it "should reply to valid request" do
95
- expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
95
+ expect { get :show, :params => { :id => 5, :session => "secret_hash" }}.not_to raise_error
96
96
  assert_response :success
97
97
  end
98
98
 
99
99
  it "should fail if required parameter is missing" do
100
- expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
100
+ expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
101
101
  end
102
102
 
103
103
  it "should pass if required parameter has wrong type" do
104
- expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
105
- expect { get :show, :id => "ten", :session => "secret_hash" }.not_to raise_error
104
+ expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
105
+ expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
106
106
  end
107
107
 
108
108
  end
@@ -115,12 +115,35 @@ describe UsersController do
115
115
  end
116
116
 
117
117
  it "should reply to valid request" do
118
- expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
118
+ expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
119
119
  assert_response :success
120
120
  end
121
121
 
122
122
  it "should fail if extra parameter is passed in" do
123
- expect { get :show, :id => 5, :session => "secret_hash", :badparam => 'badfoo' }.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
123
+ expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
124
+ end
125
+ end
126
+
127
+ context "key validations are enabled and skip on non-validated keys" do
128
+ before do
129
+ Apipie.configuration.validate_value = false
130
+ Apipie.configuration.validate_presence = true
131
+ Apipie.configuration.validate_key = true
132
+ Apipie.configuration.action_on_non_validated_keys = :skip
133
+ end
134
+
135
+ it "should reply to valid request" do
136
+ expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
137
+ assert_response :success
138
+ end
139
+
140
+ it "should delete the param and not fail if an extra parameter is passed." do
141
+ expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.not_to raise_error
142
+ expect(controller.params.as_json).to eq({"session"=>"secret_hash", "id"=>"5", "controller"=>"users", "action"=>"show"})
143
+ end
144
+
145
+ after do
146
+ Apipie.configuration.action_on_non_validated_keys = :raise
124
147
  end
125
148
  end
126
149
 
@@ -132,86 +155,80 @@ describe UsersController do
132
155
  end
133
156
 
134
157
  it "should reply to valid request" do
135
- get :show, :id => '5', :session => "secret_hash"
158
+ get :show, :params => { :id => '5', :session => "secret_hash" }
136
159
  assert_response :success
137
160
  end
138
161
 
139
162
  it "should work with nil value for a required hash param" do
140
163
  expect {
141
- get :show, :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil}
164
+ get :show, :params => { :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil} }
142
165
  }.to raise_error(Apipie::ParamInvalid, /dummy_hash/)
143
166
  assert_response :success
144
167
  end
145
168
 
146
169
  it "should fail if required parameter is missing" do
147
- expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
170
+ expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
148
171
  end
149
172
 
150
173
  it "should work with custom Type validator" do
151
174
  expect {
152
175
  get :show,
153
- :id => "not a number",
154
- :session => "secret_hash"
176
+ :params => { :id => "not a number", :session => "secret_hash" }
155
177
  }.to raise_error(Apipie::ParamError, /id/) # old-style error rather than ParamInvalid
156
178
  end
157
179
 
158
180
  it "should work with Regexp validator" do
159
- get :show,
160
- :id => 5,
161
- :session => "secret_hash",
162
- :regexp_param => "24 years"
181
+ get :show, :params => { :id => 5, :session => "secret_hash", :regexp_param => "24 years" }
163
182
  assert_response :success
164
183
 
165
184
  expect {
166
- get :show,
167
- :id => 5,
168
- :session => "secret_hash",
169
- :regexp_param => "ten years"
185
+ get :show, :params => { :id => 5,
186
+ :session => "secret_hash",
187
+ :regexp_param => "ten years" }
170
188
  }.to raise_error(Apipie::ParamInvalid, /regexp_param/)
171
189
  end
172
190
 
173
191
  it "should work with Array validator" do
174
- get :show, :id => 5, :session => "secret_hash", :array_param => "one"
175
- assert_response :success
176
- get :show, :id => 5, :session => "secret_hash", :array_param => "two"
192
+ get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "one" }
177
193
  assert_response :success
178
- get :show, :id => 5, :session => "secret_hash", :array_param => '1'
194
+ get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "two" }
179
195
  assert_response :success
180
- get :show, :id => 5, :session => "secret_hash", :boolean_param => false
196
+ get :show, :params => { :id => 5, :session => "secret_hash", :array_param => '1' }
181
197
  assert_response :success
182
198
 
183
199
  expect {
184
- get :show,
185
- :id => 5,
186
- :session => "secret_hash",
187
- :array_param => "blabla"
200
+ get :show, :params => { :id => 5,
201
+ :session => "secret_hash",
202
+ :array_param => "blabla" }
188
203
  }.to raise_error(Apipie::ParamInvalid, /array_param/)
189
204
 
190
205
  expect {
191
- get :show,
192
- :id => 5,
193
- :session => "secret_hash",
194
- :array_param => 3
206
+ get :show, :params => {
207
+ :id => 5,
208
+ :session => "secret_hash",
209
+ :array_param => 3 }
195
210
  }.to raise_error(Apipie::ParamInvalid, /array_param/)
196
211
  end
197
212
 
198
213
  it "should work with Proc validator" do
199
214
  expect {
200
215
  get :show,
201
- :id => 5,
202
- :session => "secret_hash",
203
- :proc_param => "asdgsag"
216
+ :params => {
217
+ :id => 5,
218
+ :session => "secret_hash",
219
+ :proc_param => "asdgsag" }
204
220
  }.to raise_error(Apipie::ParamInvalid, /proc_param/)
205
221
 
206
222
  get :show,
207
- :id => 5,
208
- :session => "secret_hash",
209
- :proc_param => "param value"
223
+ :params => {
224
+ :id => 5,
225
+ :session => "secret_hash",
226
+ :proc_param => "param value"}
210
227
  assert_response :success
211
228
  end
212
229
 
213
230
  it "should work with Hash validator" do
214
- post :create, :user => { :name => "root", :pass => "12345", :membership => "standard" }
231
+ post :create, params: { :user => { :name => "root", :pass => "12345", :membership => "standard" } }
215
232
  assert_response :success
216
233
 
217
234
  a = Apipie[UsersController, :create]
@@ -225,18 +242,18 @@ describe UsersController do
225
242
  hash_params[2].name == :membership
226
243
 
227
244
  expect {
228
- post :create, :user => { :name => "root", :pass => "12345", :membership => "____" }
245
+ post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } }
229
246
  }.to raise_error(Apipie::ParamInvalid, /membership/)
230
247
 
231
248
  expect {
232
- post :create, :user => { :name => "root" }
249
+ post :create, :params => { :user => { :name => "root" } }
233
250
  }.to raise_error(Apipie::ParamMissing, /pass/)
234
251
 
235
252
  expect {
236
- post :create, :user => "a string is not a hash"
253
+ post :create, :params => { :user => "a string is not a hash" }
237
254
  }.to raise_error(Apipie::ParamInvalid, /user/)
238
255
 
239
- post :create, :user => { :name => "root", :pass => "pwd" }
256
+ post :create, :params => { :user => { :name => "root", :pass => "pwd" } }
240
257
  assert_response :success
241
258
  end
242
259
 
@@ -244,10 +261,11 @@ describe UsersController do
244
261
  params = Apipie[UsersController, :create].to_json[:params]
245
262
  expect(params).to include(:name => "facts",
246
263
  :full_name => "facts",
247
- :validator => "Must be Hash",
264
+ :validator => "Must be a Hash",
248
265
  :description => "\n<p>Additional optional facts about the user</p>\n",
249
266
  :required => false,
250
267
  :allow_nil => true,
268
+ :allow_blank => false,
251
269
  :metadata => nil,
252
270
  :show => true,
253
271
  :expected_type => "hash",
@@ -256,12 +274,27 @@ describe UsersController do
256
274
 
257
275
  it "should allow nil when allow_nil is set to true" do
258
276
  post :create,
259
- :user => {
260
- :name => "root",
261
- :pass => "12345",
262
- :membership => "standard",
263
- },
264
- :facts => nil
277
+ :params => {
278
+ :user => {
279
+ :name => "root",
280
+ :pass => "12345",
281
+ :membership => "standard",
282
+ },
283
+ :facts => { :test => 'test' }
284
+ }
285
+ assert_response :success
286
+ end
287
+
288
+ it "should allow blank when allow_blank is set to true" do
289
+ post :create,
290
+ :params => {
291
+ :user => {
292
+ :name => "root",
293
+ :pass => "12345",
294
+ :membership => "standard"
295
+ },
296
+ :age => ""
297
+ }
265
298
  assert_response :success
266
299
  end
267
300
 
@@ -270,7 +303,7 @@ describe UsersController do
270
303
  context "with valid input" do
271
304
  it "should succeed" do
272
305
  put :update,
273
- {
306
+ :params => {
274
307
  :id => 5,
275
308
  :user => {
276
309
  :name => "root",
@@ -293,27 +326,27 @@ describe UsersController do
293
326
  it "should raise an error" do
294
327
  expect{
295
328
  put :update,
296
- {
297
- :id => 5,
298
- :user => {
299
- :name => "root",
300
- :pass => "12345"
301
- },
302
- :comments => [
303
- {
304
- :comment => 'comment1'
329
+ :params => {
330
+ :id => 5,
331
+ :user => {
332
+ :name => "root",
333
+ :pass => "12345"
305
334
  },
306
- {
307
- :comment => {:bad_input => 5}
308
- }
309
- ]
310
- }
335
+ :comments => [
336
+ {
337
+ :comment => {:bad_input => 4}
338
+ },
339
+ {
340
+ :comment => {:bad_input => 5}
341
+ }
342
+ ]
343
+ }
311
344
  }.to raise_error(Apipie::ParamInvalid)
312
345
  end
313
346
  end
314
347
  it "should work with empty array" do
315
348
  put :update,
316
- {
349
+ :params => {
317
350
  :id => 5,
318
351
  :user => {
319
352
  :name => "root",
@@ -441,6 +474,14 @@ describe UsersController do
441
474
  expect(a.errors[2].description).to eq("Not Found")
442
475
  end
443
476
 
477
+ it 'should recognize Rack symbols as error codes' do
478
+ a = Apipie.get_method_description(UsersController, :create)
479
+
480
+ error = a.errors.find { |e| e.code == 422 }
481
+ expect(error).to be
482
+ expect(error.description).to include("Unprocessable Entity")
483
+ end
484
+
444
485
  it "should contain all params description" do
445
486
  a = Apipie.get_method_description(UsersController, :show)
446
487
  expect(a.params.count).to eq(12)
@@ -464,7 +505,19 @@ describe UsersController do
464
505
  name: :OptionalHeaderName,
465
506
  description: 'Optional header description',
466
507
  options: {
467
- required: false
508
+ required: false,
509
+ type: "string"
510
+ }
511
+ }
512
+ end
513
+
514
+ let(:expected_header_with_default) do
515
+ {
516
+ name: :HeaderNameWithDefaultValue,
517
+ description: 'Header with default value',
518
+ options: {
519
+ required: true,
520
+ default: 'default value'
468
521
  }
469
522
  }
470
523
  end
@@ -475,6 +528,7 @@ describe UsersController do
475
528
 
476
529
  compare_hashes headers[0], expected_required_header
477
530
  compare_hashes headers[1], expected_optional_header
531
+ compare_hashes headers[2], expected_header_with_default
478
532
  end
479
533
  end
480
534
 
@@ -525,7 +579,8 @@ describe UsersController do
525
579
  :params => [{:full_name=>"oauth",
526
580
  :required=>false,
527
581
  :allow_nil => false,
528
- :validator=>"Must be String",
582
+ :allow_blank => false,
583
+ :validator=>"Must be a String",
529
584
  :description=>"\n<p>Authorization</p>\n",
530
585
  :name=>"oauth",
531
586
  :show=>true,
@@ -534,6 +589,7 @@ describe UsersController do
534
589
  :description=>"\n<p>Deprecated parameter not documented</p>\n",
535
590
  :expected_type=>"hash",
536
591
  :allow_nil=>false,
592
+ :allow_blank => false,
537
593
  :name=>"legacy_param",
538
594
  :required=>false,
539
595
  :full_name=>"legacy_param",
@@ -543,6 +599,7 @@ describe UsersController do
543
599
  :description=>"\n<p>Param description for all methods</p>\n",
544
600
  :expected_type=>"hash",
545
601
  :allow_nil=>false,
602
+ :allow_blank => false,
546
603
  :name=>"resource_param",
547
604
  :required=>false,
548
605
  :full_name=>"resource_param",
@@ -550,14 +607,16 @@ describe UsersController do
550
607
  :params=>
551
608
  [{:required=>true,
552
609
  :allow_nil => false,
553
- :validator=>"Must be String",
610
+ :allow_blank => false,
611
+ :validator=>"Must be a String",
554
612
  :description=>"\n<p>Username for login</p>\n",
555
613
  :name=>"ausername", :full_name=>"resource_param[ausername]",
556
614
  :show=>true,
557
615
  :expected_type=>"string"},
558
616
  {:required=>true,
559
617
  :allow_nil => false,
560
- :validator=>"Must be String",
618
+ :allow_blank => false,
619
+ :validator=>"Must be a String",
561
620
  :description=>"\n<p>Password for login</p>\n",
562
621
  :name=>"apassword", :full_name=>"resource_param[apassword]",
563
622
  :show=>true,
@@ -567,6 +626,7 @@ describe UsersController do
567
626
  },
568
627
  {:required=>false, :validator=>"Parameter has to be Integer.",
569
628
  :allow_nil => false,
629
+ :allow_blank => false,
570
630
  :description=>"\n<p>Company ID</p>\n",
571
631
  :name=>"id", :full_name=>"id",
572
632
  :show=>true,
@@ -690,17 +750,20 @@ EOS2
690
750
 
691
751
  describe "Parameter processing / extraction" do
692
752
  before do
753
+ Apipie.configuration.validate = true
693
754
  Apipie.configuration.process_params = true
755
+ controllers_dirname = File.expand_path('../dummy/app/controllers', File.dirname(__FILE__))
756
+ Dir.glob("#{controllers_dirname}/**/*") { |file| load(file) if File.file?(file) }
694
757
  end
695
758
 
696
759
  it "process correctly the parameters" do
697
- post :create, {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard'}, :facts => nil}
760
+ post :create, :params => {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard' }, :facts => {:test => 'test'}}
698
761
 
699
- expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => nil}.with_indifferent_access)
762
+ expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => {:test => 'test'}}.with_indifferent_access)
700
763
  end
701
764
 
702
765
  it "ignore not described parameters" do
703
- post :create, {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard', :id => 0}}
766
+ post :create, :params => {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard', :id => 0}}
704
767
 
705
768
  expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}}.with_indifferent_access)
706
769
  end
data/spec/dummy/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require File.expand_path('config/application', __dir__)
5
5
  require 'rake'
6
6
 
7
7
  Dummy::Application.load_tasks
@@ -1,8 +1,12 @@
1
1
  class ApplicationController < ActionController::Base
2
- before_filter :run_validations
2
+ before_action :run_validations
3
3
 
4
4
  resource_description do
5
5
  param :oauth, String, :desc => "Authorization", :required => false
6
+
7
+ returns :code => 401 do
8
+ property :reason, String, "Why authorization was denied"
9
+ end
6
10
  end
7
11
 
8
12
  def run_validations
@@ -3,6 +3,6 @@ class ConcernsController < ApplicationController
3
3
  resource_description { resource_id 'concern_resources' }
4
4
 
5
5
  apipie_concern_subst(:concern => 'user', :custom_subst => 'custom', 'string_subst' => 'string')
6
- include ::Concerns::SampleController
6
+ include SampleController
7
7
 
8
8
  end
@@ -0,0 +1,14 @@
1
+ class ExtendedController < ApplicationController
2
+
3
+ api :POST, '/extended'
4
+ param :user, Hash do
5
+ param :name, String
6
+ param :password, String
7
+ end
8
+ def create
9
+ end
10
+
11
+ apipie_update_params([:create]) do
12
+ param :admin, :boolean
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module ExtendingConcern
2
+ extend Apipie::DSL::Concern
3
+
4
+ update_api(:create) do
5
+ param :user, Hash do
6
+ param :from_concern, String, :desc => 'param from concern', :allow_nil => false
7
+ end
8
+ meta metadata: 'data'
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ class IncludedParamGroupController < ApplicationController
2
+ include RandomParamGroup
3
+
4
+ api :GET, '/included-param-group'
5
+ returns code:200 do
6
+ property :top_level, Array, of: Hash do
7
+ param_group :random_param_group
8
+ end
9
+ property :nested, Hash do
10
+ property :random_array, Array, of: Hash do
11
+ param_group :random_param_group
12
+ end
13
+ end
14
+ end
15
+ def show
16
+ end
17
+
18
+ end
19
+
@@ -3,7 +3,7 @@ class OverriddenConcernsController < ApplicationController
3
3
  resource_description { resource_id 'overridden_concern_resources' }
4
4
 
5
5
  apipie_concern_subst(:concern => 'user')
6
- include ::Concerns::SampleController
6
+ include SampleController
7
7
 
8
8
  def_param_group :concern do
9
9
  param :concern, String
@@ -11,7 +11,7 @@ class OverriddenConcernsController < ApplicationController
11
11
 
12
12
  api :PUT, '/:resource_id/:id'
13
13
  param :custom_parameter, String, "New parameter added by the overriding method"
14
- param_group :concern, ::Concerns::SampleController
14
+ param_group :concern, SampleController
15
15
  def update
16
16
  super
17
17
  end