diff options
author | DJ Mountney <david@twkie.net> | 2018-10-29 14:37:19 -0700 |
---|---|---|
committer | DJ Mountney <david@twkie.net> | 2018-10-29 14:37:19 -0700 |
commit | 06b6daacb15b92b04e05538b37aadfdb04fc5a4b (patch) | |
tree | 0500cf47f7d8d2e6bc7ed53cbf9ad957f07fb31a /lib/api/helpers | |
parent | c847f172d25efc211045c363f4e55402ad250c09 (diff) | |
parent | 45b61a9ece48550f51432c8cca7de7e1a298ca08 (diff) | |
download | gitlab-ce-06b6daacb15b92b04e05538b37aadfdb04fc5a4b.tar.gz |
Merge remote-tracking branch 'origin/master' into dev-master
Diffstat (limited to 'lib/api/helpers')
-rw-r--r-- | lib/api/helpers/custom_validators.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb index 23b1cd1ad45..1058f4e8a5e 100644 --- a/lib/api/helpers/custom_validators.rb +++ b/lib/api/helpers/custom_validators.rb @@ -10,8 +10,21 @@ module API raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:absence) end end + + class IntegerNoneAny < Grape::Validations::Base + def validate_param!(attr_name, params) + value = params[attr_name] + + return if value.is_a?(Integer) || + [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase) + + raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], + message: "should be an integer, 'None' or 'Any'" + end + end end end end Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence) +Grape::Validations.register_validator(:integer_none_any, ::API::Helpers::CustomValidators::IntegerNoneAny) |