grape 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +1 -0
- data/README.md +9 -1
- data/lib/grape/api.rb +12 -0
- data/lib/grape/dry_types.rb +12 -0
- data/lib/grape/dsl/headers.rb +5 -2
- data/lib/grape/dsl/helpers.rb +1 -1
- data/lib/grape/middleware/auth/dsl.rb +7 -1
- data/lib/grape/middleware/base.rb +1 -1
- data/lib/grape/util/json.rb +2 -0
- data/lib/grape/util/strict_hash_configuration.rb +1 -1
- data/lib/grape/validations/types/array_coercer.rb +0 -2
- data/lib/grape/validations/types/dry_type_coercer.rb +1 -10
- data/lib/grape/validations/types/json.rb +0 -2
- data/lib/grape/validations/types/primitive_coercer.rb +5 -7
- data/lib/grape/validations/types/set_coercer.rb +0 -3
- data/lib/grape/validations/types.rb +83 -9
- data/lib/grape/validations/validators/all_or_none_of_validator.rb +16 -0
- data/lib/grape/validations/validators/allow_blank_validator.rb +20 -0
- data/lib/grape/validations/validators/as_validator.rb +14 -0
- data/lib/grape/validations/validators/at_least_one_of_validator.rb +15 -0
- data/lib/grape/validations/validators/base.rb +73 -71
- data/lib/grape/validations/validators/coerce_validator.rb +75 -0
- data/lib/grape/validations/validators/default_validator.rb +51 -0
- data/lib/grape/validations/validators/exactly_one_of_validator.rb +17 -0
- data/lib/grape/validations/validators/except_values_validator.rb +24 -0
- data/lib/grape/validations/validators/multiple_params_base.rb +24 -22
- data/lib/grape/validations/validators/mutual_exclusion_validator.rb +16 -0
- data/lib/grape/validations/validators/presence_validator.rb +15 -0
- data/lib/grape/validations/validators/regexp_validator.rb +16 -0
- data/lib/grape/validations/validators/same_as_validator.rb +29 -0
- data/lib/grape/validations/validators/values_validator.rb +88 -0
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +59 -24
- data/spec/grape/api/custom_validations_spec.rb +77 -46
- data/spec/grape/api/deeply_included_options_spec.rb +3 -3
- data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -1
- data/spec/grape/api/invalid_format_spec.rb +2 -0
- data/spec/grape/api/recognize_path_spec.rb +1 -1
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -15
- data/spec/grape/api_remount_spec.rb +16 -15
- data/spec/grape/api_spec.rb +317 -193
- data/spec/grape/dsl/callbacks_spec.rb +1 -0
- data/spec/grape/dsl/headers_spec.rb +39 -9
- data/spec/grape/dsl/helpers_spec.rb +3 -2
- data/spec/grape/dsl/inside_route_spec.rb +6 -4
- data/spec/grape/dsl/logger_spec.rb +16 -18
- data/spec/grape/dsl/middleware_spec.rb +1 -0
- data/spec/grape/dsl/parameters_spec.rb +1 -0
- data/spec/grape/dsl/request_response_spec.rb +1 -0
- data/spec/grape/dsl/routing_spec.rb +9 -6
- data/spec/grape/endpoint/declared_spec.rb +12 -12
- data/spec/grape/endpoint_spec.rb +59 -50
- data/spec/grape/entity_spec.rb +13 -13
- data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -0
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -22
- data/spec/grape/exceptions/validation_errors_spec.rb +13 -10
- data/spec/grape/exceptions/validation_spec.rb +5 -3
- data/spec/grape/extensions/param_builders/hash_spec.rb +7 -7
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -8
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -8
- data/spec/grape/integration/rack_sendfile_spec.rb +1 -1
- data/spec/grape/loading_spec.rb +8 -8
- data/spec/grape/middleware/auth/dsl_spec.rb +14 -5
- data/spec/grape/middleware/auth/strategies_spec.rb +60 -20
- data/spec/grape/middleware/base_spec.rb +24 -15
- data/spec/grape/middleware/error_spec.rb +1 -0
- data/spec/grape/middleware/exception_spec.rb +111 -161
- data/spec/grape/middleware/formatter_spec.rb +25 -4
- data/spec/grape/middleware/globals_spec.rb +7 -4
- data/spec/grape/middleware/stack_spec.rb +11 -11
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -1
- data/spec/grape/middleware/versioner/header_spec.rb +14 -13
- data/spec/grape/middleware/versioner/param_spec.rb +7 -1
- data/spec/grape/middleware/versioner/path_spec.rb +5 -1
- data/spec/grape/middleware/versioner_spec.rb +1 -1
- data/spec/grape/parser_spec.rb +4 -0
- data/spec/grape/path_spec.rb +52 -52
- data/spec/grape/presenters/presenter_spec.rb +7 -6
- data/spec/grape/request_spec.rb +6 -4
- data/spec/grape/util/inheritable_setting_spec.rb +7 -7
- data/spec/grape/util/inheritable_values_spec.rb +3 -2
- data/spec/grape/util/reverse_stackable_values_spec.rb +3 -1
- data/spec/grape/util/stackable_values_spec.rb +7 -5
- data/spec/grape/validations/instance_behaivour_spec.rb +9 -10
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +1 -0
- data/spec/grape/validations/params_scope_spec.rb +9 -7
- data/spec/grape/validations/single_attribute_iterator_spec.rb +1 -0
- data/spec/grape/validations/types/primitive_coercer_spec.rb +2 -2
- data/spec/grape/validations/types_spec.rb +8 -8
- data/spec/grape/validations/validators/all_or_none_spec.rb +50 -56
- data/spec/grape/validations/validators/allow_blank_spec.rb +136 -140
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -56
- data/spec/grape/validations/validators/coerce_spec.rb +10 -12
- data/spec/grape/validations/validators/default_spec.rb +72 -78
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
- data/spec/grape/validations/validators/except_values_spec.rb +1 -1
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -77
- data/spec/grape/validations/validators/presence_spec.rb +16 -1
- data/spec/grape/validations/validators/regexp_spec.rb +25 -31
- data/spec/grape/validations/validators/same_as_spec.rb +14 -20
- data/spec/grape/validations/validators/values_spec.rb +172 -171
- data/spec/grape/validations_spec.rb +45 -16
- data/spec/integration/eager_load/eager_load_spec.rb +2 -2
- data/spec/integration/multi_json/json_spec.rb +1 -1
- data/spec/integration/multi_xml/xml_spec.rb +1 -1
- data/spec/shared/versioning_examples.rb +10 -7
- data/spec/spec_helper.rb +11 -1
- metadata +116 -116
- data/lib/grape/validations/types/build_coercer.rb +0 -94
- data/lib/grape/validations/validators/all_or_none.rb +0 -16
- data/lib/grape/validations/validators/allow_blank.rb +0 -18
- data/lib/grape/validations/validators/as.rb +0 -12
- data/lib/grape/validations/validators/at_least_one_of.rb +0 -15
- data/lib/grape/validations/validators/coerce.rb +0 -87
- data/lib/grape/validations/validators/default.rb +0 -49
- data/lib/grape/validations/validators/exactly_one_of.rb +0 -17
- data/lib/grape/validations/validators/except_values.rb +0 -22
- data/lib/grape/validations/validators/mutual_exclusion.rb +0 -16
- data/lib/grape/validations/validators/presence.rb +0 -13
- data/lib/grape/validations/validators/regexp.rb +0 -14
- data/lib/grape/validations/validators/same_as.rb +0 -27
- data/lib/grape/validations/validators/values.rb +0 -86
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class CoerceValidator < Base
|
7
|
+
def initialize(attrs, options, required, scope, **opts)
|
8
|
+
super
|
9
|
+
|
10
|
+
@converter = if type.is_a?(Grape::Validations::Types::VariantCollectionCoercer)
|
11
|
+
type
|
12
|
+
else
|
13
|
+
Types.build_coercer(type, method: @option[:method])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate_param!(attr_name, params)
|
18
|
+
raise validation_exception(attr_name) unless params.is_a? Hash
|
19
|
+
|
20
|
+
new_value = coerce_value(params[attr_name])
|
21
|
+
|
22
|
+
raise validation_exception(attr_name, new_value.message) unless valid_type?(new_value)
|
23
|
+
|
24
|
+
# Don't assign a value if it is identical. It fixes a problem with Hashie::Mash
|
25
|
+
# which looses wrappers for hashes and arrays after reassigning values
|
26
|
+
#
|
27
|
+
# h = Hashie::Mash.new(list: [1, 2, 3, 4])
|
28
|
+
# => #<Hashie::Mash list=#<Hashie::Array [1, 2, 3, 4]>>
|
29
|
+
# list = h.list
|
30
|
+
# h[:list] = list
|
31
|
+
# h
|
32
|
+
# => #<Hashie::Mash list=[1, 2, 3, 4]>
|
33
|
+
return if params[attr_name].instance_of?(new_value.class) && params[attr_name] == new_value
|
34
|
+
|
35
|
+
params[attr_name] = new_value
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# @!attribute [r] converter
|
41
|
+
# Object that will be used for parameter coercion and type checking.
|
42
|
+
#
|
43
|
+
# See {Types.build_coercer}
|
44
|
+
#
|
45
|
+
# @return [Object]
|
46
|
+
attr_reader :converter
|
47
|
+
|
48
|
+
def valid_type?(val)
|
49
|
+
!val.is_a?(Types::InvalidValue)
|
50
|
+
end
|
51
|
+
|
52
|
+
def coerce_value(val)
|
53
|
+
converter.call(val)
|
54
|
+
# Some custom types might fail, so it should be treated as an invalid value
|
55
|
+
rescue StandardError
|
56
|
+
Types::InvalidValue.new
|
57
|
+
end
|
58
|
+
|
59
|
+
# Type to which the parameter will be coerced.
|
60
|
+
#
|
61
|
+
# @return [Class]
|
62
|
+
def type
|
63
|
+
@option[:type].is_a?(Hash) ? @option[:type][:value] : @option[:type]
|
64
|
+
end
|
65
|
+
|
66
|
+
def validation_exception(attr_name, custom_msg = nil)
|
67
|
+
Grape::Exceptions::Validation.new(
|
68
|
+
params: [@scope.full_name(attr_name)],
|
69
|
+
message: custom_msg || message(:coerce)
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class DefaultValidator < Base
|
7
|
+
def initialize(attrs, options, required, scope, **opts)
|
8
|
+
@default = options
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate_param!(attr_name, params)
|
13
|
+
params[attr_name] = if @default.is_a? Proc
|
14
|
+
@default.call
|
15
|
+
elsif @default.frozen? || !duplicatable?(@default)
|
16
|
+
@default
|
17
|
+
else
|
18
|
+
duplicate(@default)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate!(params)
|
23
|
+
attrs = SingleAttributeIterator.new(self, @scope, params)
|
24
|
+
attrs.each do |resource_params, attr_name|
|
25
|
+
next unless @scope.meets_dependency?(resource_params, params)
|
26
|
+
|
27
|
+
validate_param!(attr_name, resource_params) if resource_params.is_a?(Hash) && resource_params[attr_name].nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# return true if we might be able to dup this object
|
34
|
+
def duplicatable?(obj)
|
35
|
+
!obj.nil? &&
|
36
|
+
obj != true &&
|
37
|
+
obj != false &&
|
38
|
+
!obj.is_a?(Symbol) &&
|
39
|
+
!obj.is_a?(Numeric)
|
40
|
+
end
|
41
|
+
|
42
|
+
# make a best effort to dup the object
|
43
|
+
def duplicate(obj)
|
44
|
+
obj.dup
|
45
|
+
rescue TypeError
|
46
|
+
obj
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class ExactlyOneOfValidator < MultipleParamsBase
|
7
|
+
def validate_params!(params)
|
8
|
+
keys = keys_in_common(params)
|
9
|
+
return if keys.length == 1
|
10
|
+
raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.length.zero?
|
11
|
+
|
12
|
+
raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class ExceptValuesValidator < Base
|
7
|
+
def initialize(attrs, options, required, scope, **opts)
|
8
|
+
@except = options.is_a?(Hash) ? options[:value] : options
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate_param!(attr_name, params)
|
13
|
+
return unless params.respond_to?(:key?) && params.key?(attr_name)
|
14
|
+
|
15
|
+
excepts = @except.is_a?(Proc) ? @except.call : @except
|
16
|
+
return if excepts.nil?
|
17
|
+
|
18
|
+
param_array = params[attr_name].nil? ? [nil] : Array.wrap(params[attr_name])
|
19
|
+
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:except_values)) if param_array.any? { |param| excepts.include?(param) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,34 +2,36 @@
|
|
2
2
|
|
3
3
|
module Grape
|
4
4
|
module Validations
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
module Validators
|
6
|
+
class MultipleParamsBase < Base
|
7
|
+
def validate!(params)
|
8
|
+
attributes = MultipleAttributesIterator.new(self, @scope, params)
|
9
|
+
array_errors = []
|
10
|
+
|
11
|
+
attributes.each do |resource_params, skip_value|
|
12
|
+
next if skip_value
|
13
|
+
|
14
|
+
begin
|
15
|
+
validate_params!(resource_params)
|
16
|
+
rescue Grape::Exceptions::Validation => e
|
17
|
+
array_errors << e
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
raise Grape::Exceptions::ValidationArrayErrors.new(array_errors) if array_errors.any?
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
+
private
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
def keys_in_common(resource_params)
|
27
|
+
return [] unless resource_params.is_a?(Hash)
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
all_keys & resource_params.keys.map! { |attr| @scope.full_name(attr) }
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def all_keys
|
33
|
+
attrs.map { |attr| @scope.full_name(attr) }
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class MutualExclusionValidator < MultipleParamsBase
|
7
|
+
def validate_params!(params)
|
8
|
+
keys = keys_in_common(params)
|
9
|
+
return if keys.length <= 1
|
10
|
+
|
11
|
+
raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class PresenceValidator < Base
|
7
|
+
def validate_param!(attr_name, params)
|
8
|
+
return if params.respond_to?(:key?) && params.key?(attr_name)
|
9
|
+
|
10
|
+
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:presence))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class RegexpValidator < Base
|
7
|
+
def validate_param!(attr_name, params)
|
8
|
+
return unless params.respond_to?(:key?) && params.key?(attr_name)
|
9
|
+
return if Array.wrap(params[attr_name]).all? { |param| param.nil? || param.to_s.match?((options_key?(:value) ? @option[:value] : @option)) }
|
10
|
+
|
11
|
+
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:regexp))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class SameAsValidator < Base
|
7
|
+
def validate_param!(attr_name, params)
|
8
|
+
confirmation = options_key?(:value) ? @option[:value] : @option
|
9
|
+
return if params[attr_name] == params[confirmation]
|
10
|
+
|
11
|
+
raise Grape::Exceptions::Validation.new(
|
12
|
+
params: [@scope.full_name(attr_name)],
|
13
|
+
message: build_message
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build_message
|
20
|
+
if options_key?(:message)
|
21
|
+
@option[:message]
|
22
|
+
else
|
23
|
+
format I18n.t(:same_as, scope: 'grape.errors.messages'), parameter: @option
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class ValuesValidator < Base
|
7
|
+
def initialize(attrs, options, required, scope, **opts)
|
8
|
+
if options.is_a?(Hash)
|
9
|
+
@excepts = options[:except]
|
10
|
+
@values = options[:value]
|
11
|
+
@proc = options[:proc]
|
12
|
+
|
13
|
+
warn '[DEPRECATION] The values validator except option is deprecated. ' \
|
14
|
+
'Use the except validator instead.' if @excepts
|
15
|
+
|
16
|
+
raise ArgumentError, 'proc must be a Proc' if @proc && !@proc.is_a?(Proc)
|
17
|
+
|
18
|
+
warn '[DEPRECATION] The values validator proc option is deprecated. ' \
|
19
|
+
'The lambda expression can now be assigned directly to values.' if @proc
|
20
|
+
else
|
21
|
+
@excepts = nil
|
22
|
+
@values = nil
|
23
|
+
@proc = nil
|
24
|
+
@values = options
|
25
|
+
end
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_param!(attr_name, params)
|
30
|
+
return unless params.is_a?(Hash)
|
31
|
+
|
32
|
+
val = params[attr_name]
|
33
|
+
|
34
|
+
return if val.nil? && !required_for_root_scope?
|
35
|
+
|
36
|
+
# don't forget that +false.blank?+ is true
|
37
|
+
return if val != false && val.blank? && @allow_blank
|
38
|
+
|
39
|
+
param_array = val.nil? ? [nil] : Array.wrap(val)
|
40
|
+
|
41
|
+
raise validation_exception(attr_name, except_message) \
|
42
|
+
unless check_excepts(param_array)
|
43
|
+
|
44
|
+
raise validation_exception(attr_name, message(:values)) \
|
45
|
+
unless check_values(param_array, attr_name)
|
46
|
+
|
47
|
+
raise validation_exception(attr_name, message(:values)) \
|
48
|
+
if @proc && !param_array.all? { |param| @proc.call(param) }
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def check_values(param_array, attr_name)
|
54
|
+
values = @values.is_a?(Proc) && @values.arity.zero? ? @values.call : @values
|
55
|
+
return true if values.nil?
|
56
|
+
|
57
|
+
begin
|
58
|
+
return param_array.all? { |param| values.call(param) } if values.is_a? Proc
|
59
|
+
rescue StandardError => e
|
60
|
+
warn "Error '#{e}' raised while validating attribute '#{attr_name}'"
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
param_array.all? { |param| values.include?(param) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_excepts(param_array)
|
67
|
+
excepts = @excepts.is_a?(Proc) ? @excepts.call : @excepts
|
68
|
+
return true if excepts.nil?
|
69
|
+
|
70
|
+
param_array.none? { |param| excepts.include?(param) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def except_message
|
74
|
+
options = instance_variable_get(:@option)
|
75
|
+
options_key?(:except_message) ? options[:except_message] : message(:except_values)
|
76
|
+
end
|
77
|
+
|
78
|
+
def required_for_root_scope?
|
79
|
+
@required && @scope.root?
|
80
|
+
end
|
81
|
+
|
82
|
+
def validation_exception(attr_name, message)
|
83
|
+
Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/grape/version.rb
CHANGED
data/lib/grape.rb
CHANGED
@@ -7,17 +7,19 @@ require 'rack/accept'
|
|
7
7
|
require 'rack/auth/basic'
|
8
8
|
require 'rack/auth/digest/md5'
|
9
9
|
require 'set'
|
10
|
+
require 'active_support'
|
10
11
|
require 'active_support/version'
|
12
|
+
require 'active_support/isolated_execution_state' if ActiveSupport::VERSION::MAJOR > 6
|
11
13
|
require 'active_support/core_ext/hash/indifferent_access'
|
12
14
|
require 'active_support/core_ext/object/blank'
|
15
|
+
require 'active_support/core_ext/array/conversions'
|
13
16
|
require 'active_support/core_ext/array/extract_options'
|
14
17
|
require 'active_support/core_ext/array/wrap'
|
15
|
-
require 'active_support/core_ext/
|
18
|
+
require 'active_support/core_ext/hash/conversions'
|
16
19
|
require 'active_support/core_ext/hash/deep_merge'
|
17
|
-
require 'active_support/core_ext/hash/reverse_merge'
|
18
20
|
require 'active_support/core_ext/hash/except'
|
21
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
19
22
|
require 'active_support/core_ext/hash/slice'
|
20
|
-
require 'active_support/core_ext/hash/conversions'
|
21
23
|
require 'active_support/dependencies/autoload'
|
22
24
|
require 'active_support/notifications'
|
23
25
|
require 'i18n'
|
@@ -43,6 +45,7 @@ module Grape
|
|
43
45
|
autoload :Env, 'grape/util/env'
|
44
46
|
autoload :Json, 'grape/util/json'
|
45
47
|
autoload :Xml, 'grape/util/xml'
|
48
|
+
autoload :DryTypes
|
46
49
|
end
|
47
50
|
|
48
51
|
module Http
|
@@ -216,6 +219,59 @@ module Grape
|
|
216
219
|
autoload :StreamResponse
|
217
220
|
end
|
218
221
|
end
|
222
|
+
|
223
|
+
module Validations
|
224
|
+
extend ::ActiveSupport::Autoload
|
225
|
+
|
226
|
+
module Types
|
227
|
+
extend ::ActiveSupport::Autoload
|
228
|
+
|
229
|
+
eager_autoload do
|
230
|
+
autoload :InvalidValue
|
231
|
+
autoload :File
|
232
|
+
autoload :Json
|
233
|
+
autoload :DryTypeCoercer
|
234
|
+
autoload :ArrayCoercer
|
235
|
+
autoload :SetCoercer
|
236
|
+
autoload :PrimitiveCoercer
|
237
|
+
autoload :CustomTypeCoercer
|
238
|
+
autoload :CustomTypeCollectionCoercer
|
239
|
+
autoload :MultipleTypeCoercer
|
240
|
+
autoload :VariantCollectionCoercer
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
eager_autoload do
|
245
|
+
autoload :AttributesIterator
|
246
|
+
autoload :MultipleAttributesIterator
|
247
|
+
autoload :SingleAttributeIterator
|
248
|
+
autoload :ParamsScope
|
249
|
+
autoload :Types
|
250
|
+
autoload :ValidatorFactory
|
251
|
+
end
|
252
|
+
|
253
|
+
module Validators
|
254
|
+
extend ::ActiveSupport::Autoload
|
255
|
+
|
256
|
+
eager_autoload do
|
257
|
+
autoload :Base
|
258
|
+
autoload :MultipleParamsBase
|
259
|
+
autoload :AllOrNoneOfValidator
|
260
|
+
autoload :AllowBlankValidator
|
261
|
+
autoload :AsValidator
|
262
|
+
autoload :AtLeastOneOfValidator
|
263
|
+
autoload :CoerceValidator
|
264
|
+
autoload :DefaultValidator
|
265
|
+
autoload :ExactlyOneOfValidator
|
266
|
+
autoload :ExceptValuesValidator
|
267
|
+
autoload :MutualExclusionValidator
|
268
|
+
autoload :PresenceValidator
|
269
|
+
autoload :RegexpValidator
|
270
|
+
autoload :SameAsValidator
|
271
|
+
autoload :ValuesValidator
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
219
275
|
end
|
220
276
|
|
221
277
|
require 'grape/config'
|
@@ -225,25 +281,4 @@ require 'grape/util/lazy_value'
|
|
225
281
|
require 'grape/util/lazy_block'
|
226
282
|
require 'grape/util/endpoint_configuration'
|
227
283
|
|
228
|
-
require 'grape/validations/validators/base'
|
229
|
-
require 'grape/validations/attributes_iterator'
|
230
|
-
require 'grape/validations/single_attribute_iterator'
|
231
|
-
require 'grape/validations/multiple_attributes_iterator'
|
232
|
-
require 'grape/validations/validators/allow_blank'
|
233
|
-
require 'grape/validations/validators/as'
|
234
|
-
require 'grape/validations/validators/at_least_one_of'
|
235
|
-
require 'grape/validations/validators/coerce'
|
236
|
-
require 'grape/validations/validators/default'
|
237
|
-
require 'grape/validations/validators/exactly_one_of'
|
238
|
-
require 'grape/validations/validators/mutual_exclusion'
|
239
|
-
require 'grape/validations/validators/presence'
|
240
|
-
require 'grape/validations/validators/regexp'
|
241
|
-
require 'grape/validations/validators/same_as'
|
242
|
-
require 'grape/validations/validators/values'
|
243
|
-
require 'grape/validations/validators/except_values'
|
244
|
-
require 'grape/validations/params_scope'
|
245
|
-
require 'grape/validations/validators/all_or_none'
|
246
|
-
require 'grape/validations/types'
|
247
|
-
require 'grape/validations/validator_factory'
|
248
|
-
|
249
284
|
require 'grape/version'
|