grape 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +41 -18
- data/UPGRADING.md +75 -1
- data/grape.gemspec +5 -5
- data/lib/grape/api/instance.rb +25 -60
- data/lib/grape/api.rb +44 -76
- data/lib/grape/cookies.rb +31 -25
- data/lib/grape/dsl/api.rb +0 -2
- data/lib/grape/dsl/desc.rb +27 -24
- data/lib/grape/dsl/headers.rb +1 -1
- data/lib/grape/dsl/helpers.rb +1 -1
- data/lib/grape/dsl/inside_route.rb +17 -40
- data/lib/grape/dsl/parameters.rb +5 -5
- data/lib/grape/dsl/routing.rb +14 -13
- data/lib/grape/endpoint.rb +100 -106
- data/lib/grape/error_formatter/base.rb +51 -21
- data/lib/grape/error_formatter/json.rb +7 -24
- data/lib/grape/error_formatter/serializable_hash.rb +7 -0
- data/lib/grape/error_formatter/txt.rb +13 -20
- data/lib/grape/error_formatter/xml.rb +3 -13
- data/lib/grape/error_formatter.rb +4 -12
- data/lib/grape/exceptions/base.rb +18 -30
- data/lib/grape/exceptions/conflicting_types.rb +11 -0
- data/lib/grape/exceptions/invalid_parameters.rb +11 -0
- data/lib/grape/exceptions/too_deep_parameters.rb +11 -0
- data/lib/grape/exceptions/unknown_auth_strategy.rb +11 -0
- data/lib/grape/exceptions/unknown_params_builder.rb +11 -0
- data/lib/grape/exceptions/validation.rb +5 -4
- data/lib/grape/exceptions/validation_errors.rb +2 -2
- data/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +2 -5
- data/lib/grape/extensions/hash.rb +2 -1
- data/lib/grape/extensions/hashie/mash.rb +3 -5
- data/lib/grape/formatter/base.rb +16 -0
- data/lib/grape/formatter/json.rb +4 -6
- data/lib/grape/formatter/serializable_hash.rb +1 -1
- data/lib/grape/formatter/txt.rb +3 -5
- data/lib/grape/formatter/xml.rb +4 -6
- data/lib/grape/formatter.rb +4 -12
- data/lib/grape/locale/en.yml +44 -44
- data/lib/grape/middleware/auth/base.rb +11 -32
- data/lib/grape/middleware/auth/dsl.rb +23 -29
- data/lib/grape/middleware/base.rb +30 -11
- data/lib/grape/middleware/error.rb +18 -24
- data/lib/grape/middleware/formatter.rb +39 -73
- data/lib/grape/middleware/stack.rb +26 -36
- data/lib/grape/middleware/versioner/accept_version_header.rb +1 -3
- data/lib/grape/middleware/versioner/base.rb +74 -0
- data/lib/grape/middleware/versioner/header.rb +4 -10
- data/lib/grape/middleware/versioner/param.rb +2 -5
- data/lib/grape/middleware/versioner/path.rb +0 -2
- data/lib/grape/middleware/versioner.rb +5 -3
- data/lib/grape/namespace.rb +1 -1
- data/lib/grape/params_builder/base.rb +18 -0
- data/lib/grape/params_builder/hash.rb +11 -0
- data/lib/grape/params_builder/hash_with_indifferent_access.rb +11 -0
- data/lib/grape/params_builder/hashie_mash.rb +11 -0
- data/lib/grape/params_builder.rb +32 -0
- data/lib/grape/parser/base.rb +16 -0
- data/lib/grape/parser/json.rb +6 -8
- data/lib/grape/parser/xml.rb +6 -8
- data/lib/grape/parser.rb +5 -7
- data/lib/grape/path.rb +39 -56
- data/lib/grape/request.rb +162 -23
- data/lib/grape/router/base_route.rb +2 -2
- data/lib/grape/router/greedy_route.rb +2 -2
- data/lib/grape/router/pattern.rb +23 -18
- data/lib/grape/router/route.rb +14 -6
- data/lib/grape/router.rb +30 -12
- data/lib/grape/util/registry.rb +27 -0
- data/lib/grape/validations/contract_scope.rb +2 -39
- data/lib/grape/validations/params_scope.rb +15 -14
- data/lib/grape/validations/types/dry_type_coercer.rb +10 -6
- data/lib/grape/validations/validator_factory.rb +2 -2
- data/lib/grape/validations/validators/allow_blank_validator.rb +1 -1
- data/lib/grape/validations/validators/base.rb +7 -11
- data/lib/grape/validations/validators/coerce_validator.rb +1 -1
- data/lib/grape/validations/validators/contract_scope_validator.rb +41 -0
- data/lib/grape/validations/validators/default_validator.rb +1 -1
- data/lib/grape/validations/validators/except_values_validator.rb +2 -2
- data/lib/grape/validations/validators/length_validator.rb +1 -1
- data/lib/grape/validations/validators/presence_validator.rb +1 -1
- data/lib/grape/validations/validators/regexp_validator.rb +2 -2
- data/lib/grape/validations/validators/values_validator.rb +15 -57
- data/lib/grape/validations.rb +8 -17
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +14 -2
- metadata +24 -16
- data/lib/grape/http/headers.rb +0 -55
- data/lib/grape/middleware/helpers.rb +0 -12
- data/lib/grape/middleware/versioner_helpers.rb +0 -75
- data/lib/grape/util/lazy/object.rb +0 -45
- data/lib/grape/validations/types/build_coercer.rb +0 -92
@@ -4,7 +4,7 @@ module Grape
|
|
4
4
|
module Validations
|
5
5
|
class ParamsScope
|
6
6
|
attr_accessor :element, :parent, :index
|
7
|
-
attr_reader :type
|
7
|
+
attr_reader :type, :params_meeting_dependency
|
8
8
|
|
9
9
|
include Grape::DSL::Parameters
|
10
10
|
|
@@ -67,6 +67,7 @@ module Grape
|
|
67
67
|
@type = opts[:type]
|
68
68
|
@group = opts[:group]
|
69
69
|
@dependent_on = opts[:dependent_on]
|
70
|
+
@params_meeting_dependency = []
|
70
71
|
@declared_params = []
|
71
72
|
@index = nil
|
72
73
|
|
@@ -94,7 +95,11 @@ module Grape
|
|
94
95
|
def meets_dependency?(params, request_params)
|
95
96
|
return true unless @dependent_on
|
96
97
|
return false if @parent.present? && !@parent.meets_dependency?(@parent.params(request_params), request_params)
|
97
|
-
|
98
|
+
|
99
|
+
if params.is_a?(Array)
|
100
|
+
@params_meeting_dependency = params.flatten.filter { |param| meets_dependency?(param, request_params) }
|
101
|
+
return @params_meeting_dependency.present?
|
102
|
+
end
|
98
103
|
|
99
104
|
meets_hash_dependency?(params)
|
100
105
|
end
|
@@ -127,7 +132,7 @@ module Grape
|
|
127
132
|
def full_name(name, index: nil)
|
128
133
|
if nested?
|
129
134
|
# Find our containing element's name, and append ours.
|
130
|
-
"#{@parent.full_name(@element)}#{brackets(
|
135
|
+
"#{@parent.full_name(@element)}#{brackets(index || @index)}#{brackets(name)}"
|
131
136
|
elsif lateral?
|
132
137
|
# Find the name of the element as if it was at the same nesting level
|
133
138
|
# as our parent. We need to forward our index upward to achieve this.
|
@@ -174,16 +179,12 @@ module Grape
|
|
174
179
|
|
175
180
|
# Adds a parameter declaration to our list of validations.
|
176
181
|
# @param attrs [Array] (see Grape::DSL::Parameters#requires)
|
177
|
-
def push_declared_params(attrs,
|
178
|
-
opts =
|
179
|
-
if lateral?
|
180
|
-
@parent.push_declared_params(attrs, **opts)
|
181
|
-
else
|
182
|
-
push_renamed_param(full_path + [attrs.first], opts[:as]) \
|
183
|
-
if opts && opts[:as]
|
182
|
+
def push_declared_params(attrs, opts = {})
|
183
|
+
opts[:declared_params_scope] = self unless opts.key?(:declared_params_scope)
|
184
|
+
return @parent.push_declared_params(attrs, opts) if lateral?
|
184
185
|
|
185
|
-
|
186
|
-
|
186
|
+
push_renamed_param(full_path + [attrs.first], opts[:as]) if opts[:as]
|
187
|
+
@declared_params.concat(attrs.map { |attr| ::Grape::Validations::ParamsScope::Attr.new(attr, opts[:declared_params_scope]) })
|
187
188
|
end
|
188
189
|
|
189
190
|
# Get the full path of the parameter scope in the hierarchy.
|
@@ -490,7 +491,7 @@ module Grape
|
|
490
491
|
def validate_value_coercion(coerce_type, *values_list)
|
491
492
|
return unless coerce_type
|
492
493
|
|
493
|
-
coerce_type = coerce_type.first if coerce_type.is_a?(
|
494
|
+
coerce_type = coerce_type.first if coerce_type.is_a?(Enumerable)
|
494
495
|
values_list.each do |values|
|
495
496
|
next if !values || values.is_a?(Proc)
|
496
497
|
|
@@ -529,7 +530,7 @@ module Grape
|
|
529
530
|
def validates_presence(validations, attrs, doc, opts)
|
530
531
|
return unless validations.key?(:presence) && validations[:presence]
|
531
532
|
|
532
|
-
validate(
|
533
|
+
validate('presence', validations.delete(:presence), attrs, doc, opts)
|
533
534
|
validations.delete(:message) if validations.key?(:message)
|
534
535
|
end
|
535
536
|
end
|
@@ -22,16 +22,20 @@ module Grape
|
|
22
22
|
# collection_coercer_for(Array)
|
23
23
|
# #=> Grape::Validations::Types::ArrayCoercer
|
24
24
|
def collection_coercer_for(type)
|
25
|
-
|
25
|
+
case type
|
26
|
+
when Array
|
27
|
+
ArrayCoercer
|
28
|
+
when Set
|
29
|
+
SetCoercer
|
30
|
+
else
|
31
|
+
raise ArgumentError, "Unknown type: #{type}"
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
# Returns an instance of a coercer for a given type
|
29
36
|
def coercer_instance_for(type, strict = false)
|
30
|
-
|
31
|
-
|
32
|
-
# in case of a collection (Array[Integer]) the type is an instance of a collection,
|
33
|
-
# so we need to figure out the actual type
|
34
|
-
collection_coercer_for(type.class).new(type, strict)
|
37
|
+
klass = type.instance_of?(Class) ? PrimitiveCoercer : collection_coercer_for(type)
|
38
|
+
klass.new(type, strict)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Grape
|
4
4
|
module Validations
|
5
5
|
class ValidatorFactory
|
6
|
-
def self.create_validator(
|
6
|
+
def self.create_validator(options)
|
7
7
|
options[:validator_class].new(options[:attributes],
|
8
8
|
options[:options],
|
9
9
|
options[:required],
|
10
10
|
options[:params_scope],
|
11
|
-
|
11
|
+
options[:opts])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -8,7 +8,7 @@ module Grape
|
|
8
8
|
return if (options_key?(:value) ? @option[:value] : @option) || !params.is_a?(Hash)
|
9
9
|
|
10
10
|
value = params[attr_name]
|
11
|
-
value = value.
|
11
|
+
value = value.scrub if value.respond_to?(:scrub)
|
12
12
|
|
13
13
|
return if value == false || value.present?
|
14
14
|
|
@@ -13,15 +13,14 @@ module Grape
|
|
13
13
|
# @param options [Object] implementation-dependent Validator options
|
14
14
|
# @param required [Boolean] attribute(s) are required or optional
|
15
15
|
# @param scope [ParamsScope] parent scope for this Validator
|
16
|
-
# @param opts [
|
17
|
-
def initialize(attrs, options, required, scope,
|
16
|
+
# @param opts [Hash] additional validation options
|
17
|
+
def initialize(attrs, options, required, scope, opts)
|
18
18
|
@attrs = Array(attrs)
|
19
19
|
@option = options
|
20
20
|
@required = required
|
21
21
|
@scope = scope
|
22
|
-
|
23
|
-
@
|
24
|
-
@allow_blank = opts.fetch(:allow_blank, false)
|
22
|
+
@fail_fast = opts[:fail_fast]
|
23
|
+
@allow_blank = opts[:allow_blank]
|
25
24
|
end
|
26
25
|
|
27
26
|
# Validates a given request.
|
@@ -50,7 +49,7 @@ module Grape
|
|
50
49
|
next if !@scope.required? && empty_val
|
51
50
|
next unless @scope.meets_dependency?(val, params)
|
52
51
|
|
53
|
-
validate_param!(attr_name, val) if @required ||
|
52
|
+
validate_param!(attr_name, val) if @required || val.try(:key?, attr_name)
|
54
53
|
rescue Grape::Exceptions::Validation => e
|
55
54
|
array_errors << e
|
56
55
|
end
|
@@ -60,10 +59,7 @@ module Grape
|
|
60
59
|
|
61
60
|
def self.inherited(klass)
|
62
61
|
super
|
63
|
-
|
64
|
-
|
65
|
-
short_validator_name = klass.name.demodulize.underscore.delete_suffix('_validator')
|
66
|
-
Validations.register_validator(short_validator_name, klass)
|
62
|
+
Validations.register(klass)
|
67
63
|
end
|
68
64
|
|
69
65
|
def message(default_key = nil)
|
@@ -73,7 +69,7 @@ module Grape
|
|
73
69
|
|
74
70
|
def options_key?(key, options = nil)
|
75
71
|
options = instance_variable_get(:@option) if options.nil?
|
76
|
-
options.
|
72
|
+
options.try(:key?, key) && !options[key].nil?
|
77
73
|
end
|
78
74
|
|
79
75
|
def fail_fast?
|
@@ -4,7 +4,7 @@ module Grape
|
|
4
4
|
module Validations
|
5
5
|
module Validators
|
6
6
|
class CoerceValidator < Base
|
7
|
-
def initialize(attrs, options, required, scope,
|
7
|
+
def initialize(attrs, options, required, scope, opts)
|
8
8
|
super
|
9
9
|
|
10
10
|
@converter = if type.is_a?(Grape::Validations::Types::VariantCollectionCoercer)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grape
|
4
|
+
module Validations
|
5
|
+
module Validators
|
6
|
+
class ContractScopeValidator < Base
|
7
|
+
attr_reader :schema
|
8
|
+
|
9
|
+
def initialize(_attrs, _options, _required, _scope, opts)
|
10
|
+
super
|
11
|
+
@schema = opts.fetch(:schema)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Validates a given request.
|
15
|
+
# @param request [Grape::Request] the request currently being handled
|
16
|
+
# @raise [Grape::Exceptions::ValidationArrayErrors] if validation failed
|
17
|
+
# @return [void]
|
18
|
+
def validate(request)
|
19
|
+
res = schema.call(request.params)
|
20
|
+
|
21
|
+
if res.success?
|
22
|
+
request.params.deep_merge!(res.to_h)
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
raise Grape::Exceptions::ValidationArrayErrors.new(build_errors_from_messages(res.errors.messages))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def build_errors_from_messages(messages)
|
32
|
+
messages.map do |message|
|
33
|
+
full_name = message.path.first.to_s
|
34
|
+
full_name << "[#{message.path[1..].join('][')}]" if message.path.size > 1
|
35
|
+
Grape::Exceptions::Validation.new(params: [full_name], message: message.text)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -4,13 +4,13 @@ module Grape
|
|
4
4
|
module Validations
|
5
5
|
module Validators
|
6
6
|
class ExceptValuesValidator < Base
|
7
|
-
def initialize(attrs, options, required, scope,
|
7
|
+
def initialize(attrs, options, required, scope, opts)
|
8
8
|
@except = options.is_a?(Hash) ? options[:value] : options
|
9
9
|
super
|
10
10
|
end
|
11
11
|
|
12
12
|
def validate_param!(attr_name, params)
|
13
|
-
return unless params.
|
13
|
+
return unless params.try(:key?, attr_name)
|
14
14
|
|
15
15
|
excepts = @except.is_a?(Proc) ? @except.call : @except
|
16
16
|
return if excepts.nil?
|
@@ -5,7 +5,7 @@ module Grape
|
|
5
5
|
module Validators
|
6
6
|
class PresenceValidator < Base
|
7
7
|
def validate_param!(attr_name, params)
|
8
|
-
return if params.
|
8
|
+
return if params.try(:key?, attr_name)
|
9
9
|
|
10
10
|
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:presence))
|
11
11
|
end
|
@@ -5,8 +5,8 @@ module Grape
|
|
5
5
|
module Validators
|
6
6
|
class RegexpValidator < Base
|
7
7
|
def validate_param!(attr_name, params)
|
8
|
-
return unless params.
|
9
|
-
return if Array.wrap(params[attr_name]).all? { |param| param.nil? || param.to_s.match?((options_key?(:value) ? @option[:value] : @option)) }
|
8
|
+
return unless params.try(:key?, attr_name)
|
9
|
+
return if Array.wrap(params[attr_name]).all? { |param| param.nil? || param.to_s.scrub.match?((options_key?(:value) ? @option[:value] : @option)) }
|
10
10
|
|
11
11
|
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:regexp))
|
12
12
|
end
|
@@ -4,23 +4,8 @@ module Grape
|
|
4
4
|
module Validations
|
5
5
|
module Validators
|
6
6
|
class ValuesValidator < Base
|
7
|
-
def initialize(attrs, options, required, scope,
|
8
|
-
|
9
|
-
@excepts = options[:except]
|
10
|
-
@values = options[:value]
|
11
|
-
@proc = options[:proc]
|
12
|
-
|
13
|
-
Grape.deprecator.warn('The values validator except option is deprecated. Use the except validator instead.') if @excepts
|
14
|
-
|
15
|
-
raise ArgumentError, 'proc must be a Proc' if @proc && !@proc.is_a?(Proc)
|
16
|
-
|
17
|
-
Grape.deprecator.warn('The values validator proc option is deprecated. The lambda expression can now be assigned directly to values.') if @proc
|
18
|
-
else
|
19
|
-
@excepts = nil
|
20
|
-
@values = nil
|
21
|
-
@proc = nil
|
22
|
-
@values = options
|
23
|
-
end
|
7
|
+
def initialize(attrs, options, required, scope, opts)
|
8
|
+
@values = options.is_a?(Hash) ? options[:value] : options
|
24
9
|
super
|
25
10
|
end
|
26
11
|
|
@@ -31,57 +16,34 @@ module Grape
|
|
31
16
|
|
32
17
|
return if val.nil? && !required_for_root_scope?
|
33
18
|
|
19
|
+
val = val.scrub if val.respond_to?(:scrub)
|
20
|
+
|
34
21
|
# don't forget that +false.blank?+ is true
|
35
22
|
return if val != false && val.blank? && @allow_blank
|
36
23
|
|
37
|
-
|
38
|
-
|
39
|
-
raise validation_exception(attr_name, except_message) \
|
40
|
-
unless check_excepts(param_array)
|
41
|
-
|
42
|
-
raise validation_exception(attr_name, message(:values)) \
|
43
|
-
unless check_values(param_array, attr_name)
|
24
|
+
return if check_values?(val, attr_name)
|
44
25
|
|
45
|
-
raise
|
46
|
-
|
26
|
+
raise Grape::Exceptions::Validation.new(
|
27
|
+
params: [@scope.full_name(attr_name)],
|
28
|
+
message: message(:values)
|
29
|
+
)
|
47
30
|
end
|
48
31
|
|
49
32
|
private
|
50
33
|
|
51
|
-
def check_values(
|
34
|
+
def check_values?(val, attr_name)
|
52
35
|
values = @values.is_a?(Proc) && @values.arity.zero? ? @values.call : @values
|
53
36
|
return true if values.nil?
|
54
37
|
|
38
|
+
param_array = val.nil? ? [nil] : Array.wrap(val)
|
39
|
+
return param_array.all? { |param| values.include?(param) } unless values.is_a?(Proc)
|
40
|
+
|
55
41
|
begin
|
56
|
-
|
42
|
+
param_array.all? { |param| values.call(param) }
|
57
43
|
rescue StandardError => e
|
58
44
|
warn "Error '#{e}' raised while validating attribute '#{attr_name}'"
|
59
|
-
|
45
|
+
false
|
60
46
|
end
|
61
|
-
param_array.all? { |param| values.include?(param) }
|
62
|
-
end
|
63
|
-
|
64
|
-
def check_excepts(param_array)
|
65
|
-
excepts = @excepts.is_a?(Proc) ? @excepts.call : @excepts
|
66
|
-
return true if excepts.nil?
|
67
|
-
|
68
|
-
param_array.none? { |param| excepts.include?(param) }
|
69
|
-
end
|
70
|
-
|
71
|
-
def validate_proc(proc, param_array)
|
72
|
-
case proc.arity
|
73
|
-
when 0
|
74
|
-
param_array.all? { |_param| proc.call }
|
75
|
-
when 1
|
76
|
-
param_array.all? { |param| proc.call(param) }
|
77
|
-
else
|
78
|
-
raise ArgumentError, 'proc arity must be 0 or 1'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def except_message
|
83
|
-
options = instance_variable_get(:@option)
|
84
|
-
options_key?(:except_message) ? options[:except_message] : message(:except_values)
|
85
47
|
end
|
86
48
|
|
87
49
|
def required_for_root_scope?
|
@@ -92,10 +54,6 @@ module Grape
|
|
92
54
|
|
93
55
|
scope.root?
|
94
56
|
end
|
95
|
-
|
96
|
-
def validation_exception(attr_name, message)
|
97
|
-
Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message)
|
98
|
-
end
|
99
57
|
end
|
100
58
|
end
|
101
59
|
end
|
data/lib/grape/validations.rb
CHANGED
@@ -2,29 +2,20 @@
|
|
2
2
|
|
3
3
|
module Grape
|
4
4
|
module Validations
|
5
|
+
extend Grape::Util::Registry
|
6
|
+
|
5
7
|
module_function
|
6
8
|
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
9
|
+
def require_validator(short_name)
|
10
|
+
raise Grape::Exceptions::UnknownValidator, short_name unless registry.key?(short_name)
|
10
11
|
|
11
|
-
|
12
|
-
# @param short_name [String] all lower-case, no spaces
|
13
|
-
# @param klass [Class] the validator class. Should inherit from
|
14
|
-
# Grape::Validations::Validators::Base.
|
15
|
-
def register_validator(short_name, klass)
|
16
|
-
validators[short_name] = klass
|
12
|
+
registry[short_name]
|
17
13
|
end
|
18
14
|
|
19
|
-
def
|
20
|
-
|
21
|
-
end
|
15
|
+
def build_short_name(klass)
|
16
|
+
return if klass.name.blank?
|
22
17
|
|
23
|
-
|
24
|
-
str_name = short_name.to_s
|
25
|
-
validators.fetch(str_name) { Grape::Validations::Validators.const_get(:"#{str_name.camelize}Validator") }
|
26
|
-
rescue NameError
|
27
|
-
raise Grape::Exceptions::UnknownValidator, short_name
|
18
|
+
klass.name.demodulize.underscore.delete_suffix('_validator')
|
28
19
|
end
|
29
20
|
end
|
30
21
|
end
|
data/lib/grape/version.rb
CHANGED
data/lib/grape.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
3
4
|
require 'active_support'
|
4
5
|
require 'active_support/concern'
|
5
6
|
require 'active_support/configurable'
|
@@ -19,6 +20,7 @@ require 'active_support/core_ext/hash/slice'
|
|
19
20
|
require 'active_support/core_ext/module/delegation'
|
20
21
|
require 'active_support/core_ext/object/blank'
|
21
22
|
require 'active_support/core_ext/object/deep_dup'
|
23
|
+
require 'active_support/core_ext/object/try'
|
22
24
|
require 'active_support/core_ext/object/duplicable'
|
23
25
|
require 'active_support/core_ext/string/output_safety'
|
24
26
|
require 'active_support/core_ext/string/exclude'
|
@@ -33,7 +35,6 @@ require 'date'
|
|
33
35
|
require 'dry-types'
|
34
36
|
require 'forwardable'
|
35
37
|
require 'json'
|
36
|
-
require 'logger'
|
37
38
|
require 'mustermann/grape'
|
38
39
|
require 'pathname'
|
39
40
|
require 'rack'
|
@@ -58,12 +59,23 @@ I18n.load_path << File.expand_path('grape/locale/en.yml', __dir__)
|
|
58
59
|
module Grape
|
59
60
|
include ActiveSupport::Configurable
|
60
61
|
|
62
|
+
HTTP_SUPPORTED_METHODS = [
|
63
|
+
Rack::GET,
|
64
|
+
Rack::POST,
|
65
|
+
Rack::PUT,
|
66
|
+
Rack::PATCH,
|
67
|
+
Rack::DELETE,
|
68
|
+
Rack::HEAD,
|
69
|
+
Rack::OPTIONS
|
70
|
+
].freeze
|
71
|
+
|
61
72
|
def self.deprecator
|
62
73
|
@deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Grape')
|
63
74
|
end
|
64
75
|
|
65
76
|
configure do |config|
|
66
|
-
config.param_builder =
|
77
|
+
config.param_builder = :hash_with_indifferent_access
|
78
|
+
config.lint = false
|
67
79
|
config.compile_methods!
|
68
80
|
end
|
69
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -16,14 +15,14 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '6'
|
18
|
+
version: '6.1'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '6'
|
25
|
+
version: '6.1'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: dry-types
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,14 +119,17 @@ files:
|
|
120
119
|
- lib/grape/error_formatter.rb
|
121
120
|
- lib/grape/error_formatter/base.rb
|
122
121
|
- lib/grape/error_formatter/json.rb
|
122
|
+
- lib/grape/error_formatter/serializable_hash.rb
|
123
123
|
- lib/grape/error_formatter/txt.rb
|
124
124
|
- lib/grape/error_formatter/xml.rb
|
125
125
|
- lib/grape/exceptions/base.rb
|
126
|
+
- lib/grape/exceptions/conflicting_types.rb
|
126
127
|
- lib/grape/exceptions/empty_message_body.rb
|
127
128
|
- lib/grape/exceptions/incompatible_option_values.rb
|
128
129
|
- lib/grape/exceptions/invalid_accept_header.rb
|
129
130
|
- lib/grape/exceptions/invalid_formatter.rb
|
130
131
|
- lib/grape/exceptions/invalid_message_body.rb
|
132
|
+
- lib/grape/exceptions/invalid_parameters.rb
|
131
133
|
- lib/grape/exceptions/invalid_response.rb
|
132
134
|
- lib/grape/exceptions/invalid_version_header.rb
|
133
135
|
- lib/grape/exceptions/invalid_versioner_option.rb
|
@@ -137,9 +139,12 @@ files:
|
|
137
139
|
- lib/grape/exceptions/missing_mime_type.rb
|
138
140
|
- lib/grape/exceptions/missing_option.rb
|
139
141
|
- lib/grape/exceptions/missing_vendor_option.rb
|
142
|
+
- lib/grape/exceptions/too_deep_parameters.rb
|
140
143
|
- lib/grape/exceptions/too_many_multipart_files.rb
|
144
|
+
- lib/grape/exceptions/unknown_auth_strategy.rb
|
141
145
|
- lib/grape/exceptions/unknown_options.rb
|
142
146
|
- lib/grape/exceptions/unknown_parameter.rb
|
147
|
+
- lib/grape/exceptions/unknown_params_builder.rb
|
143
148
|
- lib/grape/exceptions/unknown_validator.rb
|
144
149
|
- lib/grape/exceptions/unsupported_group_type.rb
|
145
150
|
- lib/grape/exceptions/validation.rb
|
@@ -149,11 +154,11 @@ files:
|
|
149
154
|
- lib/grape/extensions/hash.rb
|
150
155
|
- lib/grape/extensions/hashie/mash.rb
|
151
156
|
- lib/grape/formatter.rb
|
157
|
+
- lib/grape/formatter/base.rb
|
152
158
|
- lib/grape/formatter/json.rb
|
153
159
|
- lib/grape/formatter/serializable_hash.rb
|
154
160
|
- lib/grape/formatter/txt.rb
|
155
161
|
- lib/grape/formatter/xml.rb
|
156
|
-
- lib/grape/http/headers.rb
|
157
162
|
- lib/grape/json.rb
|
158
163
|
- lib/grape/locale/en.yml
|
159
164
|
- lib/grape/middleware/auth/base.rb
|
@@ -165,16 +170,21 @@ files:
|
|
165
170
|
- lib/grape/middleware/filter.rb
|
166
171
|
- lib/grape/middleware/formatter.rb
|
167
172
|
- lib/grape/middleware/globals.rb
|
168
|
-
- lib/grape/middleware/helpers.rb
|
169
173
|
- lib/grape/middleware/stack.rb
|
170
174
|
- lib/grape/middleware/versioner.rb
|
171
175
|
- lib/grape/middleware/versioner/accept_version_header.rb
|
176
|
+
- lib/grape/middleware/versioner/base.rb
|
172
177
|
- lib/grape/middleware/versioner/header.rb
|
173
178
|
- lib/grape/middleware/versioner/param.rb
|
174
179
|
- lib/grape/middleware/versioner/path.rb
|
175
|
-
- lib/grape/middleware/versioner_helpers.rb
|
176
180
|
- lib/grape/namespace.rb
|
181
|
+
- lib/grape/params_builder.rb
|
182
|
+
- lib/grape/params_builder/base.rb
|
183
|
+
- lib/grape/params_builder/hash.rb
|
184
|
+
- lib/grape/params_builder/hash_with_indifferent_access.rb
|
185
|
+
- lib/grape/params_builder/hashie_mash.rb
|
177
186
|
- lib/grape/parser.rb
|
187
|
+
- lib/grape/parser/base.rb
|
178
188
|
- lib/grape/parser/json.rb
|
179
189
|
- lib/grape/parser/xml.rb
|
180
190
|
- lib/grape/path.rb
|
@@ -197,12 +207,12 @@ files:
|
|
197
207
|
- lib/grape/util/inheritable_setting.rb
|
198
208
|
- lib/grape/util/inheritable_values.rb
|
199
209
|
- lib/grape/util/lazy/block.rb
|
200
|
-
- lib/grape/util/lazy/object.rb
|
201
210
|
- lib/grape/util/lazy/value.rb
|
202
211
|
- lib/grape/util/lazy/value_array.rb
|
203
212
|
- lib/grape/util/lazy/value_enumerable.rb
|
204
213
|
- lib/grape/util/lazy/value_hash.rb
|
205
214
|
- lib/grape/util/media_type.rb
|
215
|
+
- lib/grape/util/registry.rb
|
206
216
|
- lib/grape/util/reverse_stackable_values.rb
|
207
217
|
- lib/grape/util/stackable_values.rb
|
208
218
|
- lib/grape/util/strict_hash_configuration.rb
|
@@ -215,7 +225,6 @@ files:
|
|
215
225
|
- lib/grape/validations/single_attribute_iterator.rb
|
216
226
|
- lib/grape/validations/types.rb
|
217
227
|
- lib/grape/validations/types/array_coercer.rb
|
218
|
-
- lib/grape/validations/types/build_coercer.rb
|
219
228
|
- lib/grape/validations/types/custom_type_coercer.rb
|
220
229
|
- lib/grape/validations/types/custom_type_collection_coercer.rb
|
221
230
|
- lib/grape/validations/types/dry_type_coercer.rb
|
@@ -233,6 +242,7 @@ files:
|
|
233
242
|
- lib/grape/validations/validators/at_least_one_of_validator.rb
|
234
243
|
- lib/grape/validations/validators/base.rb
|
235
244
|
- lib/grape/validations/validators/coerce_validator.rb
|
245
|
+
- lib/grape/validations/validators/contract_scope_validator.rb
|
236
246
|
- lib/grape/validations/validators/default_validator.rb
|
237
247
|
- lib/grape/validations/validators/exactly_one_of_validator.rb
|
238
248
|
- lib/grape/validations/validators/except_values_validator.rb
|
@@ -250,11 +260,10 @@ licenses:
|
|
250
260
|
- MIT
|
251
261
|
metadata:
|
252
262
|
bug_tracker_uri: https://github.com/ruby-grape/grape/issues
|
253
|
-
changelog_uri: https://github.com/ruby-grape/grape/blob/v2.
|
254
|
-
documentation_uri: https://www.rubydoc.info/gems/grape/2.
|
255
|
-
source_code_uri: https://github.com/ruby-grape/grape/tree/v2.
|
263
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v2.4.0/CHANGELOG.md
|
264
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/2.4.0
|
265
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v2.4.0
|
256
266
|
rubygems_mfa_required: 'true'
|
257
|
-
post_install_message:
|
258
267
|
rdoc_options: []
|
259
268
|
require_paths:
|
260
269
|
- lib
|
@@ -269,8 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
278
|
- !ruby/object:Gem::Version
|
270
279
|
version: '0'
|
271
280
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
273
|
-
signing_key:
|
281
|
+
rubygems_version: 3.6.9
|
274
282
|
specification_version: 4
|
275
283
|
summary: A simple Ruby framework for building REST-like APIs.
|
276
284
|
test_files: []
|