@@ -230,63 +230,61 @@ def tags(*args)
230
230
def _apipie_define_validators ( description )
231
231
232
232
# [re]define method only if validation is turned on
233
- if description && ( Apipie . configuration . validate == true ||
234
- Apipie . configuration . validate == :implicitly ||
235
- Apipie . configuration . validate == :explicitly )
236
-
237
- _apipie_save_method_params ( description . method , description . params )
238
-
239
- unless instance_methods . include? ( :apipie_validations )
240
- define_method ( :apipie_validations ) do
241
- method_params = self . class . _apipie_get_method_params ( action_name )
242
-
243
- if Apipie . configuration . validate_presence?
244
- Validator ::BaseValidator . raise_if_missing_params do |missing |
245
- method_params . each_value do |param |
246
- # check if required parameters are present
247
- missing << param if param . required && !params . key? ( param . name )
248
- end
249
- end
250
- end
233
+ return unless description && [ true , :implicitly , :explicitly ] . include? ( Apipie . configuration . validate )
234
+
235
+ _apipie_save_method_params ( description . method , description . params )
251
236
252
- if Apipie . configuration . validate_value?
237
+ unless instance_methods . include? ( :apipie_validations )
238
+ define_method ( :apipie_validations ) do
239
+ method_params = self . class . _apipie_get_method_params ( action_name )
240
+
241
+ if Apipie . configuration . validate_presence?
242
+ Validator ::BaseValidator . raise_if_missing_params do |missing |
253
243
method_params . each_value do |param |
254
- # params validations
255
- param . validate ( params [ :" #{ param . name } " ] ) if params . key? ( param . name )
244
+ # check if required parameters are present
245
+ missing << param if param . required && ! params . key? ( param . name )
256
246
end
257
247
end
248
+ end
258
249
259
- # Only allow params passed in that are defined keys in the api
260
- # Auto skip the default params (format, controller, action)
261
- if Apipie . configuration . validate_key?
262
- params . reject { |k , _ | %w[ format controller action ] . include? ( k . to_s ) } . each_pair do |param , _ |
263
- # params allowed
264
- if method_params . none? { |_ , p | p . name . to_s == param . to_s }
265
- self . class . _apipie_handle_validate_key_error params , param
266
- end
267
- end
250
+ if Apipie . configuration . validate_value?
251
+ method_params . each_value do |param |
252
+ # params validations
253
+ param . validate ( params [ :"#{ param . name } " ] ) if params . key? ( param . name )
268
254
end
255
+ end
269
256
270
- return unless Apipie . configuration . process_value?
271
- @api_params ||= { }
272
- method_params . each_value do |param |
273
- # params processing
274
- @api_params [ param . as ] = param . process_value ( params [ :"#{ param . name } " ] ) if params . key? ( param . name )
257
+ # Only allow params passed in that are defined keys in the api
258
+ # Auto skip the default params (format, controller, action)
259
+ if Apipie . configuration . validate_key?
260
+ params . reject { |k , _ | %w[ format controller action ] . include? ( k . to_s ) } . each_pair do |param , _ |
261
+ # params allowed
262
+ if method_params . none? { |_ , p | p . name . to_s == param . to_s }
263
+ self . class . _apipie_handle_validate_key_error params , param
264
+ end
275
265
end
276
266
end
267
+
268
+ return unless Apipie . configuration . process_value?
269
+ @api_params ||= { }
270
+ method_params . each_value do |param |
271
+ # params processing
272
+ @api_params [ param . as ] = param . process_value ( params [ :"#{ param . name } " ] ) if params . key? ( param . name )
273
+ end
277
274
end
275
+ end
278
276
279
- if Apipie . configuration . validate == :implicitly || Apipie . configuration . validate == true
280
- old_method = instance_method ( description . method )
277
+ return unless [ :implicitly , true ] . include? ( Apipie . configuration . validate )
278
+ old_method = instance_method ( description . method )
281
279
282
- define_method ( description . method ) do |*args |
283
- apipie_validations
280
+ define_method ( description . method ) do |*args |
281
+ apipie_validations
284
282
285
- # run the original method code
286
- old_method . bind ( self ) . call ( *args )
287
- end
288
- end
283
+ # run the original method code
284
+ old_method . bind ( self ) . call ( *args )
289
285
end
286
+
287
+
290
288
end
291
289
292
290
def _apipie_handle_validate_key_error params , param
0 commit comments