Sha256: 36712fc11f28006296f55b28a73fc0c3842ae8c08870b24d9ecc022493bf20d4
Contents?: true
Size: 962 Bytes
Versions: 9
Compression:
Stored size: 962 Bytes
Contents
require 'grape/validations' module Grape::Validators class Json < Grape::Validations::Base def validate_param!(field, params) begin JSON.parse( params[field] ) rescue fail Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be valid JSON!' end end end class JsonArray < Grape::Validations::Base def validate_param!(field, params) begin raise unless JSON.parse( params[field] ).kind_of? Array rescue fail Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be a valid JSON array!' end end end class JsonHash < Grape::Validations::Base def validate_param!(field, params) begin raise unless JSON.parse( params[field] ).kind_of? Hash rescue fail Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be a valid JSON hash!' end end end end
Version data entries
9 entries across 9 versions & 1 rubygems