grape 1.5.3 → 1.7.1
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 +92 -0
- data/CONTRIBUTING.md +32 -1
- data/README.md +176 -25
- data/UPGRADING.md +61 -4
- data/grape.gemspec +6 -6
- data/lib/grape/api/instance.rb +14 -18
- data/lib/grape/api.rb +17 -12
- data/lib/grape/cookies.rb +2 -0
- data/lib/grape/dry_types.rb +12 -0
- data/lib/grape/dsl/api.rb +0 -2
- data/lib/grape/dsl/callbacks.rb +0 -2
- data/lib/grape/dsl/configuration.rb +0 -2
- data/lib/grape/dsl/desc.rb +4 -20
- data/lib/grape/dsl/headers.rb +5 -2
- data/lib/grape/dsl/helpers.rb +7 -7
- data/lib/grape/dsl/inside_route.rb +43 -30
- data/lib/grape/dsl/middleware.rb +4 -6
- data/lib/grape/dsl/parameters.rb +13 -10
- data/lib/grape/dsl/request_response.rb +9 -8
- data/lib/grape/dsl/routing.rb +6 -4
- data/lib/grape/dsl/settings.rb +5 -7
- data/lib/grape/dsl/validations.rb +0 -15
- data/lib/grape/endpoint.rb +22 -37
- data/lib/grape/error_formatter/json.rb +9 -7
- data/lib/grape/error_formatter/xml.rb +2 -6
- data/lib/grape/exceptions/base.rb +3 -2
- data/lib/grape/exceptions/missing_group_type.rb +8 -1
- data/lib/grape/exceptions/too_many_multipart_files.rb +11 -0
- data/lib/grape/exceptions/unsupported_group_type.rb +8 -1
- data/lib/grape/exceptions/validation.rb +1 -6
- data/lib/grape/formatter/json.rb +1 -0
- data/lib/grape/formatter/serializable_hash.rb +2 -1
- data/lib/grape/formatter/xml.rb +1 -0
- data/lib/grape/locale/en.yml +9 -8
- data/lib/grape/middleware/auth/dsl.rb +7 -2
- data/lib/grape/middleware/base.rb +3 -1
- data/lib/grape/middleware/error.rb +2 -2
- data/lib/grape/middleware/formatter.rb +4 -4
- data/lib/grape/middleware/stack.rb +3 -3
- data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
- data/lib/grape/middleware/versioner/header.rb +6 -4
- data/lib/grape/middleware/versioner/param.rb +1 -0
- data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
- data/lib/grape/middleware/versioner/path.rb +2 -0
- data/lib/grape/path.rb +1 -0
- data/lib/grape/request.rb +4 -1
- data/lib/grape/router/attribute_translator.rb +1 -1
- data/lib/grape/router/pattern.rb +1 -1
- data/lib/grape/router/route.rb +2 -2
- data/lib/grape/router.rb +6 -0
- data/lib/grape/types/invalid_value.rb +8 -0
- data/lib/grape/util/cache.rb +1 -1
- data/lib/grape/util/inheritable_setting.rb +1 -3
- data/lib/grape/util/json.rb +2 -0
- data/lib/grape/util/lazy_value.rb +3 -2
- data/lib/grape/util/strict_hash_configuration.rb +1 -1
- data/lib/grape/validations/attributes_doc.rb +58 -0
- data/lib/grape/validations/params_scope.rb +138 -79
- data/lib/grape/validations/types/array_coercer.rb +0 -2
- data/lib/grape/validations/types/custom_type_coercer.rb +1 -0
- data/lib/grape/validations/types/dry_type_coercer.rb +4 -8
- data/lib/grape/validations/types/invalid_value.rb +0 -7
- data/lib/grape/validations/types/json.rb +2 -1
- data/lib/grape/validations/types/primitive_coercer.rb +16 -8
- data/lib/grape/validations/types/set_coercer.rb +0 -2
- data/lib/grape/validations/types.rb +98 -30
- 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 +82 -70
- 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 -20
- 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/validations.rb +16 -6
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +77 -29
- data/spec/grape/api/custom_validations_spec.rb +116 -45
- data/spec/grape/api/deeply_included_options_spec.rb +3 -5
- data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -3
- data/spec/grape/api/documentation_spec.rb +59 -0
- data/spec/grape/api/inherited_helpers_spec.rb +0 -2
- data/spec/grape/api/instance_spec.rb +0 -1
- data/spec/grape/api/invalid_format_spec.rb +2 -2
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/nested_helpers_spec.rb +0 -2
- data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/parameters_modification_spec.rb +0 -2
- data/spec/grape/api/patch_method_helpers_spec.rb +0 -2
- data/spec/grape/api/recognize_path_spec.rb +1 -3
- data/spec/grape/api/required_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -2
- data/spec/grape/api/routes_with_requirements_spec.rb +8 -10
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -17
- data/spec/grape/api/shared_helpers_spec.rb +0 -2
- data/spec/grape/api_remount_spec.rb +16 -16
- data/spec/grape/api_spec.rb +462 -251
- data/spec/grape/config_spec.rb +0 -2
- data/spec/grape/dsl/callbacks_spec.rb +2 -3
- data/spec/grape/dsl/desc_spec.rb +2 -2
- data/spec/grape/dsl/headers_spec.rb +39 -11
- data/spec/grape/dsl/helpers_spec.rb +3 -4
- data/spec/grape/dsl/inside_route_spec.rb +16 -16
- data/spec/grape/dsl/logger_spec.rb +15 -19
- data/spec/grape/dsl/middleware_spec.rb +2 -3
- data/spec/grape/dsl/parameters_spec.rb +2 -2
- data/spec/grape/dsl/request_response_spec.rb +7 -8
- data/spec/grape/dsl/routing_spec.rb +11 -10
- data/spec/grape/dsl/settings_spec.rb +0 -2
- data/spec/grape/dsl/validations_spec.rb +0 -17
- data/spec/grape/endpoint/declared_spec.rb +261 -16
- data/spec/grape/endpoint_spec.rb +88 -59
- data/spec/grape/entity_spec.rb +22 -23
- data/spec/grape/exceptions/base_spec.rb +16 -2
- data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -2
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +64 -24
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_response_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -3
- data/spec/grape/exceptions/missing_group_type_spec.rb +21 -0
- data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -2
- data/spec/grape/exceptions/missing_option_spec.rb +1 -3
- data/spec/grape/exceptions/unknown_options_spec.rb +0 -2
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -2
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +23 -0
- data/spec/grape/exceptions/validation_errors_spec.rb +13 -11
- data/spec/grape/exceptions/validation_spec.rb +5 -5
- data/spec/grape/extensions/param_builders/hash_spec.rb +7 -9
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -10
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -10
- data/spec/grape/integration/global_namespace_function_spec.rb +0 -2
- data/spec/grape/integration/rack_sendfile_spec.rb +1 -3
- data/spec/grape/integration/rack_spec.rb +6 -7
- data/spec/grape/loading_spec.rb +8 -10
- data/spec/grape/middleware/auth/base_spec.rb +0 -1
- data/spec/grape/middleware/auth/dsl_spec.rb +15 -8
- data/spec/grape/middleware/auth/strategies_spec.rb +60 -22
- data/spec/grape/middleware/base_spec.rb +28 -19
- data/spec/grape/middleware/error_spec.rb +8 -3
- data/spec/grape/middleware/exception_spec.rb +111 -163
- data/spec/grape/middleware/formatter_spec.rb +33 -14
- data/spec/grape/middleware/globals_spec.rb +7 -6
- data/spec/grape/middleware/stack_spec.rb +14 -14
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -3
- data/spec/grape/middleware/versioner/header_spec.rb +30 -15
- data/spec/grape/middleware/versioner/param_spec.rb +7 -3
- data/spec/grape/middleware/versioner/path_spec.rb +5 -3
- data/spec/grape/middleware/versioner_spec.rb +1 -3
- data/spec/grape/named_api_spec.rb +0 -2
- data/spec/grape/parser_spec.rb +4 -2
- data/spec/grape/path_spec.rb +52 -54
- data/spec/grape/presenters/presenter_spec.rb +7 -8
- data/spec/grape/request_spec.rb +6 -6
- data/spec/grape/util/inheritable_setting_spec.rb +7 -8
- data/spec/grape/util/inheritable_values_spec.rb +3 -3
- data/spec/grape/util/reverse_stackable_values_spec.rb +3 -2
- data/spec/grape/util/stackable_values_spec.rb +7 -6
- data/spec/grape/util/strict_hash_configuration_spec.rb +0 -1
- data/spec/grape/validations/attributes_doc_spec.rb +153 -0
- data/spec/grape/validations/instance_behaivour_spec.rb +9 -12
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +1 -2
- data/spec/grape/validations/params_scope_spec.rb +361 -96
- data/spec/grape/validations/single_attribute_iterator_spec.rb +2 -3
- data/spec/grape/validations/types/array_coercer_spec.rb +0 -2
- data/spec/grape/validations/types/primitive_coercer_spec.rb +24 -9
- data/spec/grape/validations/types/set_coercer_spec.rb +0 -2
- data/spec/grape/validations/types_spec.rb +36 -10
- data/spec/grape/validations/validators/all_or_none_spec.rb +50 -58
- data/spec/grape/validations/validators/allow_blank_spec.rb +135 -141
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -58
- data/spec/grape/validations/validators/coerce_spec.rb +23 -24
- data/spec/grape/validations/validators/default_spec.rb +72 -80
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -79
- data/spec/grape/validations/validators/except_values_spec.rb +3 -5
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -79
- data/spec/grape/validations/validators/presence_spec.rb +16 -3
- data/spec/grape/validations/validators/regexp_spec.rb +25 -33
- data/spec/grape/validations/validators/same_as_spec.rb +14 -22
- data/spec/grape/validations/validators/values_spec.rb +201 -179
- data/spec/grape/validations_spec.rb +171 -79
- data/spec/integration/eager_load/eager_load_spec.rb +2 -2
- data/spec/integration/multi_json/json_spec.rb +1 -3
- data/spec/integration/multi_xml/xml_spec.rb +1 -3
- data/spec/shared/versioning_examples.rb +12 -9
- data/spec/spec_helper.rb +21 -6
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- metadata +41 -29
- data/lib/grape/validations/validators/all_or_none.rb +0 -15
- data/lib/grape/validations/validators/allow_blank.rb +0 -18
- data/lib/grape/validations/validators/as.rb +0 -16
- data/lib/grape/validations/validators/at_least_one_of.rb +0 -14
- data/lib/grape/validations/validators/coerce.rb +0 -91
- data/lib/grape/validations/validators/default.rb +0 -48
- data/lib/grape/validations/validators/exactly_one_of.rb +0 -16
- data/lib/grape/validations/validators/except_values.rb +0 -22
- data/lib/grape/validations/validators/mutual_exclusion.rb +0 -15
- data/lib/grape/validations/validators/presence.rb +0 -12
- data/lib/grape/validations/validators/regexp.rb +0 -13
- data/lib/grape/validations/validators/same_as.rb +0 -26
- data/lib/grape/validations/validators/values.rb +0 -83
- data/spec/grape/dsl/configuration_spec.rb +0 -16
- data/spec/grape/validations/attributes_iterator_spec.rb +0 -6
- data/spec/support/eager_load.rb +0 -19
@@ -35,14 +35,14 @@ shared_examples_for 'versioning' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
versioned_get '/awesome', 'v1', **macro_options
|
38
|
-
expect(last_response.status).to
|
38
|
+
expect(last_response.status).to be 404
|
39
39
|
|
40
40
|
versioned_get '/awesome', 'v2', **macro_options
|
41
|
-
expect(last_response.status).to
|
41
|
+
expect(last_response.status).to be 200
|
42
42
|
versioned_get '/legacy', 'v1', **macro_options
|
43
|
-
expect(last_response.status).to
|
43
|
+
expect(last_response.status).to be 200
|
44
44
|
versioned_get '/legacy', 'v2', **macro_options
|
45
|
-
expect(last_response.status).to
|
45
|
+
expect(last_response.status).to be 404
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'is able to specify multiple versions' do
|
@@ -52,11 +52,11 @@ shared_examples_for 'versioning' do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
versioned_get '/awesome', 'v1', **macro_options
|
55
|
-
expect(last_response.status).to
|
55
|
+
expect(last_response.status).to be 200
|
56
56
|
versioned_get '/awesome', 'v2', **macro_options
|
57
|
-
expect(last_response.status).to
|
57
|
+
expect(last_response.status).to be 200
|
58
58
|
versioned_get '/awesome', 'v3', **macro_options
|
59
|
-
expect(last_response.status).to
|
59
|
+
expect(last_response.status).to be 404
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'with different versions for the same endpoint' do
|
@@ -70,7 +70,7 @@ shared_examples_for 'versioning' do
|
|
70
70
|
|
71
71
|
subject.version 'v1', macro_options do
|
72
72
|
get 'version' do
|
73
|
-
|
73
|
+
"version #{request.env['api.version']}"
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -94,7 +94,7 @@ shared_examples_for 'versioning' do
|
|
94
94
|
|
95
95
|
subject.version 'v1', macro_options do
|
96
96
|
get 'version' do
|
97
|
-
|
97
|
+
"version #{request.env['api.version']}"
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -117,6 +117,7 @@ shared_examples_for 'versioning' do
|
|
117
117
|
before do
|
118
118
|
@output ||= 'v2-'
|
119
119
|
end
|
120
|
+
|
120
121
|
get 'version' do
|
121
122
|
@output += 'version'
|
122
123
|
end
|
@@ -126,6 +127,7 @@ shared_examples_for 'versioning' do
|
|
126
127
|
before do
|
127
128
|
@output ||= 'v1-'
|
128
129
|
end
|
130
|
+
|
129
131
|
get 'version' do
|
130
132
|
@output += 'version'
|
131
133
|
end
|
@@ -170,6 +172,7 @@ shared_examples_for 'versioning' do
|
|
170
172
|
end
|
171
173
|
klass
|
172
174
|
end
|
175
|
+
|
173
176
|
before do
|
174
177
|
subject.format :txt
|
175
178
|
|
data/spec/spec_helper.rb
CHANGED
@@ -5,17 +5,24 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
5
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support'))
|
6
6
|
|
7
7
|
require 'grape'
|
8
|
+
require 'test_prof/recipes/rspec/let_it_be'
|
9
|
+
|
10
|
+
class NullAdapter
|
11
|
+
def begin_transaction; end
|
12
|
+
|
13
|
+
def rollback_transaction; end
|
14
|
+
end
|
15
|
+
|
16
|
+
TestProf::BeforeAll.adapter = NullAdapter.new
|
8
17
|
|
9
18
|
require 'rubygems'
|
10
19
|
require 'bundler'
|
11
20
|
Bundler.require :default, :test
|
12
21
|
|
13
|
-
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
|
22
|
+
Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each do |file|
|
14
23
|
require file
|
15
24
|
end
|
16
25
|
|
17
|
-
eager_load!
|
18
|
-
|
19
26
|
# The default value for this setting is true in a standard Rails app,
|
20
27
|
# so it should be set to true here as well to reflect that.
|
21
28
|
I18n.enforce_available_locales = true
|
@@ -27,11 +34,19 @@ RSpec.configure do |config|
|
|
27
34
|
config.filter_run_when_matching :focus
|
28
35
|
config.warnings = true
|
29
36
|
|
30
|
-
config.before(:
|
37
|
+
config.before(:all) { Grape::Util::InheritableSetting.reset_global! }
|
38
|
+
config.before { Grape::Util::InheritableSetting.reset_global! }
|
31
39
|
|
32
40
|
# Enable flags like --only-failures and --next-failure
|
33
41
|
config.example_status_persistence_file_path = '.rspec_status'
|
34
42
|
end
|
35
43
|
|
36
|
-
require '
|
37
|
-
|
44
|
+
require 'simplecov'
|
45
|
+
require 'simplecov-lcov'
|
46
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
47
|
+
c.report_with_single_file = true
|
48
|
+
c.single_report_path = 'coverage/lcov.info'
|
49
|
+
end
|
50
|
+
|
51
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
52
|
+
SimpleCov.start
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -73,6 +73,9 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 1.3.0
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '3'
|
76
79
|
type: :runtime
|
77
80
|
prerelease: false
|
78
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -80,6 +83,9 @@ dependencies:
|
|
80
83
|
- - ">="
|
81
84
|
- !ruby/object:Gem::Version
|
82
85
|
version: 1.3.0
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: rack-accept
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +121,7 @@ files:
|
|
115
121
|
- lib/grape/config.rb
|
116
122
|
- lib/grape/content_types.rb
|
117
123
|
- lib/grape/cookies.rb
|
124
|
+
- lib/grape/dry_types.rb
|
118
125
|
- lib/grape/dsl/api.rb
|
119
126
|
- lib/grape/dsl/callbacks.rb
|
120
127
|
- lib/grape/dsl/configuration.rb
|
@@ -151,6 +158,7 @@ files:
|
|
151
158
|
- lib/grape/exceptions/missing_mime_type.rb
|
152
159
|
- lib/grape/exceptions/missing_option.rb
|
153
160
|
- lib/grape/exceptions/missing_vendor_option.rb
|
161
|
+
- lib/grape/exceptions/too_many_multipart_files.rb
|
154
162
|
- lib/grape/exceptions/unknown_options.rb
|
155
163
|
- lib/grape/exceptions/unknown_parameter.rb
|
156
164
|
- lib/grape/exceptions/unknown_validator.rb
|
@@ -201,6 +209,7 @@ files:
|
|
201
209
|
- lib/grape/serve_stream/file_body.rb
|
202
210
|
- lib/grape/serve_stream/sendfile_response.rb
|
203
211
|
- lib/grape/serve_stream/stream_response.rb
|
212
|
+
- lib/grape/types/invalid_value.rb
|
204
213
|
- lib/grape/util/base_inheritable.rb
|
205
214
|
- lib/grape/util/cache.rb
|
206
215
|
- lib/grape/util/endpoint_configuration.rb
|
@@ -217,6 +226,7 @@ files:
|
|
217
226
|
- lib/grape/util/strict_hash_configuration.rb
|
218
227
|
- lib/grape/util/xml.rb
|
219
228
|
- lib/grape/validations.rb
|
229
|
+
- lib/grape/validations/attributes_doc.rb
|
220
230
|
- lib/grape/validations/attributes_iterator.rb
|
221
231
|
- lib/grape/validations/multiple_attributes_iterator.rb
|
222
232
|
- lib/grape/validations/params_scope.rb
|
@@ -235,25 +245,26 @@ files:
|
|
235
245
|
- lib/grape/validations/types/set_coercer.rb
|
236
246
|
- lib/grape/validations/types/variant_collection_coercer.rb
|
237
247
|
- lib/grape/validations/validator_factory.rb
|
238
|
-
- lib/grape/validations/validators/
|
239
|
-
- lib/grape/validations/validators/
|
240
|
-
- lib/grape/validations/validators/
|
241
|
-
- lib/grape/validations/validators/
|
248
|
+
- lib/grape/validations/validators/all_or_none_of_validator.rb
|
249
|
+
- lib/grape/validations/validators/allow_blank_validator.rb
|
250
|
+
- lib/grape/validations/validators/as_validator.rb
|
251
|
+
- lib/grape/validations/validators/at_least_one_of_validator.rb
|
242
252
|
- lib/grape/validations/validators/base.rb
|
243
|
-
- lib/grape/validations/validators/
|
244
|
-
- lib/grape/validations/validators/
|
245
|
-
- lib/grape/validations/validators/
|
246
|
-
- lib/grape/validations/validators/
|
253
|
+
- lib/grape/validations/validators/coerce_validator.rb
|
254
|
+
- lib/grape/validations/validators/default_validator.rb
|
255
|
+
- lib/grape/validations/validators/exactly_one_of_validator.rb
|
256
|
+
- lib/grape/validations/validators/except_values_validator.rb
|
247
257
|
- lib/grape/validations/validators/multiple_params_base.rb
|
248
|
-
- lib/grape/validations/validators/
|
249
|
-
- lib/grape/validations/validators/
|
250
|
-
- lib/grape/validations/validators/
|
251
|
-
- lib/grape/validations/validators/
|
252
|
-
- lib/grape/validations/validators/
|
258
|
+
- lib/grape/validations/validators/mutual_exclusion_validator.rb
|
259
|
+
- lib/grape/validations/validators/presence_validator.rb
|
260
|
+
- lib/grape/validations/validators/regexp_validator.rb
|
261
|
+
- lib/grape/validations/validators/same_as_validator.rb
|
262
|
+
- lib/grape/validations/validators/values_validator.rb
|
253
263
|
- lib/grape/version.rb
|
254
264
|
- spec/grape/api/custom_validations_spec.rb
|
255
265
|
- spec/grape/api/deeply_included_options_spec.rb
|
256
266
|
- spec/grape/api/defines_boolean_in_params_spec.rb
|
267
|
+
- spec/grape/api/documentation_spec.rb
|
257
268
|
- spec/grape/api/inherited_helpers_spec.rb
|
258
269
|
- spec/grape/api/instance_spec.rb
|
259
270
|
- spec/grape/api/invalid_format_spec.rb
|
@@ -272,7 +283,6 @@ files:
|
|
272
283
|
- spec/grape/api_spec.rb
|
273
284
|
- spec/grape/config_spec.rb
|
274
285
|
- spec/grape/dsl/callbacks_spec.rb
|
275
|
-
- spec/grape/dsl/configuration_spec.rb
|
276
286
|
- spec/grape/dsl/desc_spec.rb
|
277
287
|
- spec/grape/dsl/headers_spec.rb
|
278
288
|
- spec/grape/dsl/helpers_spec.rb
|
@@ -293,10 +303,12 @@ files:
|
|
293
303
|
- spec/grape/exceptions/invalid_formatter_spec.rb
|
294
304
|
- spec/grape/exceptions/invalid_response_spec.rb
|
295
305
|
- spec/grape/exceptions/invalid_versioner_option_spec.rb
|
306
|
+
- spec/grape/exceptions/missing_group_type_spec.rb
|
296
307
|
- spec/grape/exceptions/missing_mime_type_spec.rb
|
297
308
|
- spec/grape/exceptions/missing_option_spec.rb
|
298
309
|
- spec/grape/exceptions/unknown_options_spec.rb
|
299
310
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
311
|
+
- spec/grape/exceptions/unsupported_group_type_spec.rb
|
300
312
|
- spec/grape/exceptions/validation_errors_spec.rb
|
301
313
|
- spec/grape/exceptions/validation_spec.rb
|
302
314
|
- spec/grape/extensions/param_builders/hash_spec.rb
|
@@ -330,7 +342,7 @@ files:
|
|
330
342
|
- spec/grape/util/reverse_stackable_values_spec.rb
|
331
343
|
- spec/grape/util/stackable_values_spec.rb
|
332
344
|
- spec/grape/util/strict_hash_configuration_spec.rb
|
333
|
-
- spec/grape/validations/
|
345
|
+
- spec/grape/validations/attributes_doc_spec.rb
|
334
346
|
- spec/grape/validations/instance_behaivour_spec.rb
|
335
347
|
- spec/grape/validations/multiple_attributes_iterator_spec.rb
|
336
348
|
- spec/grape/validations/params_scope_spec.rb
|
@@ -361,7 +373,6 @@ files:
|
|
361
373
|
- spec/support/basic_auth_encode_helpers.rb
|
362
374
|
- spec/support/chunks.rb
|
363
375
|
- spec/support/content_type_helpers.rb
|
364
|
-
- spec/support/eager_load.rb
|
365
376
|
- spec/support/endpoint_faker.rb
|
366
377
|
- spec/support/file_streamer.rb
|
367
378
|
- spec/support/integer_helpers.rb
|
@@ -371,10 +382,10 @@ licenses:
|
|
371
382
|
- MIT
|
372
383
|
metadata:
|
373
384
|
bug_tracker_uri: https://github.com/ruby-grape/grape/issues
|
374
|
-
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.
|
375
|
-
documentation_uri: https://www.rubydoc.info/gems/grape/1.
|
376
|
-
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.
|
377
|
-
post_install_message:
|
385
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.7.1/CHANGELOG.md
|
386
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/1.7.1
|
387
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.7.1
|
388
|
+
post_install_message:
|
378
389
|
rdoc_options: []
|
379
390
|
require_paths:
|
380
391
|
- lib
|
@@ -382,15 +393,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
382
393
|
requirements:
|
383
394
|
- - ">="
|
384
395
|
- !ruby/object:Gem::Version
|
385
|
-
version: 2.
|
396
|
+
version: 2.6.0
|
386
397
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
387
398
|
requirements:
|
388
399
|
- - ">="
|
389
400
|
- !ruby/object:Gem::Version
|
390
401
|
version: '0'
|
391
402
|
requirements: []
|
392
|
-
rubygems_version: 3.
|
393
|
-
signing_key:
|
403
|
+
rubygems_version: 3.0.3
|
404
|
+
signing_key:
|
394
405
|
specification_version: 4
|
395
406
|
summary: A simple Ruby framework for building REST-like APIs.
|
396
407
|
test_files:
|
@@ -405,7 +416,6 @@ test_files:
|
|
405
416
|
- spec/support/file_streamer.rb
|
406
417
|
- spec/support/versioned_helpers.rb
|
407
418
|
- spec/support/content_type_helpers.rb
|
408
|
-
- spec/support/eager_load.rb
|
409
419
|
- spec/support/integer_helpers.rb
|
410
420
|
- spec/grape/middleware/error_spec.rb
|
411
421
|
- spec/grape/middleware/globals_spec.rb
|
@@ -435,6 +445,8 @@ test_files:
|
|
435
445
|
- spec/grape/integration/global_namespace_function_spec.rb
|
436
446
|
- spec/grape/validations_spec.rb
|
437
447
|
- spec/grape/entity_spec.rb
|
448
|
+
- spec/grape/exceptions/missing_group_type_spec.rb
|
449
|
+
- spec/grape/exceptions/unsupported_group_type_spec.rb
|
438
450
|
- spec/grape/exceptions/validation_spec.rb
|
439
451
|
- spec/grape/exceptions/invalid_accept_header_spec.rb
|
440
452
|
- spec/grape/exceptions/missing_option_spec.rb
|
@@ -449,10 +461,10 @@ test_files:
|
|
449
461
|
- spec/grape/exceptions/base_spec.rb
|
450
462
|
- spec/grape/presenters/presenter_spec.rb
|
451
463
|
- spec/grape/validations/single_attribute_iterator_spec.rb
|
452
|
-
- spec/grape/validations/attributes_iterator_spec.rb
|
453
464
|
- spec/grape/validations/types/primitive_coercer_spec.rb
|
454
465
|
- spec/grape/validations/types/set_coercer_spec.rb
|
455
466
|
- spec/grape/validations/types/array_coercer_spec.rb
|
467
|
+
- spec/grape/validations/attributes_doc_spec.rb
|
456
468
|
- spec/grape/validations/params_scope_spec.rb
|
457
469
|
- spec/grape/validations/instance_behaivour_spec.rb
|
458
470
|
- spec/grape/validations/multiple_attributes_iterator_spec.rb
|
@@ -493,12 +505,12 @@ test_files:
|
|
493
505
|
- spec/grape/api/routes_with_requirements_spec.rb
|
494
506
|
- spec/grape/api/custom_validations_spec.rb
|
495
507
|
- spec/grape/api/optional_parameters_in_route_spec.rb
|
508
|
+
- spec/grape/api/documentation_spec.rb
|
496
509
|
- spec/grape/api_remount_spec.rb
|
497
510
|
- spec/grape/named_api_spec.rb
|
498
511
|
- spec/grape/dsl/request_response_spec.rb
|
499
512
|
- spec/grape/dsl/desc_spec.rb
|
500
513
|
- spec/grape/dsl/logger_spec.rb
|
501
|
-
- spec/grape/dsl/configuration_spec.rb
|
502
514
|
- spec/grape/dsl/validations_spec.rb
|
503
515
|
- spec/grape/dsl/parameters_spec.rb
|
504
516
|
- spec/grape/dsl/helpers_spec.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'grape/validations/validators/multiple_params_base'
|
4
|
-
|
5
|
-
module Grape
|
6
|
-
module Validations
|
7
|
-
class AllOrNoneOfValidator < MultipleParamsBase
|
8
|
-
def validate_params!(params)
|
9
|
-
keys = keys_in_common(params)
|
10
|
-
return if keys.empty? || keys.length == all_keys.length
|
11
|
-
raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:all_or_none))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class AllowBlankValidator < Base
|
6
|
-
def validate_param!(attr_name, params)
|
7
|
-
return if (options_key?(:value) ? @option[:value] : @option) || !params.is_a?(Hash)
|
8
|
-
|
9
|
-
value = params[attr_name]
|
10
|
-
value = value.strip if value.respond_to?(:strip)
|
11
|
-
|
12
|
-
return if value == false || value.present?
|
13
|
-
|
14
|
-
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:blank))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class AsValidator < Base
|
6
|
-
def initialize(attrs, options, required, scope, **opts)
|
7
|
-
@renamed_options = options
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
|
-
def validate_param!(attr_name, params)
|
12
|
-
params[@renamed_options] = params[attr_name]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'grape/validations/validators/multiple_params_base'
|
4
|
-
|
5
|
-
module Grape
|
6
|
-
module Validations
|
7
|
-
class AtLeastOneOfValidator < MultipleParamsBase
|
8
|
-
def validate_params!(params)
|
9
|
-
return unless keys_in_common(params).empty?
|
10
|
-
raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:at_least_one))
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
class API
|
5
|
-
class Boolean
|
6
|
-
def self.build(val)
|
7
|
-
return nil if val != true && val != false
|
8
|
-
|
9
|
-
new
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Instance
|
14
|
-
Boolean = Grape::API::Boolean
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Validations
|
19
|
-
class CoerceValidator < Base
|
20
|
-
def initialize(attrs, options, required, scope, **opts)
|
21
|
-
super
|
22
|
-
|
23
|
-
@converter = if type.is_a?(Grape::Validations::Types::VariantCollectionCoercer)
|
24
|
-
type
|
25
|
-
else
|
26
|
-
Types.build_coercer(type, method: @option[:method])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def validate(request)
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
|
-
def validate_param!(attr_name, params)
|
35
|
-
raise validation_exception(attr_name) unless params.is_a? Hash
|
36
|
-
|
37
|
-
new_value = coerce_value(params[attr_name])
|
38
|
-
|
39
|
-
raise validation_exception(attr_name, new_value.message) unless valid_type?(new_value)
|
40
|
-
|
41
|
-
# Don't assign a value if it is identical. It fixes a problem with Hashie::Mash
|
42
|
-
# which looses wrappers for hashes and arrays after reassigning values
|
43
|
-
#
|
44
|
-
# h = Hashie::Mash.new(list: [1, 2, 3, 4])
|
45
|
-
# => #<Hashie::Mash list=#<Hashie::Array [1, 2, 3, 4]>>
|
46
|
-
# list = h.list
|
47
|
-
# h[:list] = list
|
48
|
-
# h
|
49
|
-
# => #<Hashie::Mash list=[1, 2, 3, 4]>
|
50
|
-
return if params[attr_name].class == new_value.class && params[attr_name] == new_value
|
51
|
-
|
52
|
-
params[attr_name] = new_value
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
# @!attribute [r] converter
|
58
|
-
# Object that will be used for parameter coercion and type checking.
|
59
|
-
#
|
60
|
-
# See {Types.build_coercer}
|
61
|
-
#
|
62
|
-
# @return [Object]
|
63
|
-
attr_reader :converter
|
64
|
-
|
65
|
-
def valid_type?(val)
|
66
|
-
!val.is_a?(Types::InvalidValue)
|
67
|
-
end
|
68
|
-
|
69
|
-
def coerce_value(val)
|
70
|
-
converter.call(val)
|
71
|
-
# Some custom types might fail, so it should be treated as an invalid value
|
72
|
-
rescue StandardError
|
73
|
-
Types::InvalidValue.new
|
74
|
-
end
|
75
|
-
|
76
|
-
# Type to which the parameter will be coerced.
|
77
|
-
#
|
78
|
-
# @return [Class]
|
79
|
-
def type
|
80
|
-
@option[:type].is_a?(Hash) ? @option[:type][:value] : @option[:type]
|
81
|
-
end
|
82
|
-
|
83
|
-
def validation_exception(attr_name, custom_msg = nil)
|
84
|
-
Grape::Exceptions::Validation.new(
|
85
|
-
params: [@scope.full_name(attr_name)],
|
86
|
-
message: custom_msg || message(:coerce)
|
87
|
-
)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class DefaultValidator < Base
|
6
|
-
def initialize(attrs, options, required, scope, **opts)
|
7
|
-
@default = options
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
|
-
def validate_param!(attr_name, params)
|
12
|
-
params[attr_name] = if @default.is_a? Proc
|
13
|
-
@default.call
|
14
|
-
elsif @default.frozen? || !duplicatable?(@default)
|
15
|
-
@default
|
16
|
-
else
|
17
|
-
duplicate(@default)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def validate!(params)
|
22
|
-
attrs = SingleAttributeIterator.new(self, @scope, params)
|
23
|
-
attrs.each do |resource_params, attr_name|
|
24
|
-
next unless @scope.meets_dependency?(resource_params, params)
|
25
|
-
validate_param!(attr_name, resource_params) if resource_params.is_a?(Hash) && resource_params[attr_name].nil?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
# return true if we might be able to dup this object
|
32
|
-
def duplicatable?(obj)
|
33
|
-
!obj.nil? &&
|
34
|
-
obj != true &&
|
35
|
-
obj != false &&
|
36
|
-
!obj.is_a?(Symbol) &&
|
37
|
-
!obj.is_a?(Numeric)
|
38
|
-
end
|
39
|
-
|
40
|
-
# make a best effort to dup the object
|
41
|
-
def duplicate(obj)
|
42
|
-
obj.dup
|
43
|
-
rescue TypeError
|
44
|
-
obj
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'grape/validations/validators/multiple_params_base'
|
4
|
-
|
5
|
-
module Grape
|
6
|
-
module Validations
|
7
|
-
class ExactlyOneOfValidator < MultipleParamsBase
|
8
|
-
def validate_params!(params)
|
9
|
-
keys = keys_in_common(params)
|
10
|
-
return if keys.length == 1
|
11
|
-
raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.length.zero?
|
12
|
-
raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class ExceptValuesValidator < Base
|
6
|
-
def initialize(attrs, options, required, scope, **opts)
|
7
|
-
@except = options.is_a?(Hash) ? options[:value] : options
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
|
-
def validate_param!(attr_name, params)
|
12
|
-
return unless params.respond_to?(:key?) && params.key?(attr_name)
|
13
|
-
|
14
|
-
excepts = @except.is_a?(Proc) ? @except.call : @except
|
15
|
-
return if excepts.nil?
|
16
|
-
|
17
|
-
param_array = params[attr_name].nil? ? [nil] : Array.wrap(params[attr_name])
|
18
|
-
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:except_values)) if param_array.any? { |param| excepts.include?(param) }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'grape/validations/validators/multiple_params_base'
|
4
|
-
|
5
|
-
module Grape
|
6
|
-
module Validations
|
7
|
-
class MutualExclusionValidator < MultipleParamsBase
|
8
|
-
def validate_params!(params)
|
9
|
-
keys = keys_in_common(params)
|
10
|
-
return if keys.length <= 1
|
11
|
-
raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class PresenceValidator < Base
|
6
|
-
def validate_param!(attr_name, params)
|
7
|
-
return if params.respond_to?(:key?) && params.key?(attr_name)
|
8
|
-
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:presence))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class RegexpValidator < Base
|
6
|
-
def validate_param!(attr_name, params)
|
7
|
-
return unless params.respond_to?(:key?) && params.key?(attr_name)
|
8
|
-
return if Array.wrap(params[attr_name]).all? { |param| param.nil? || param.to_s.match?((options_key?(:value) ? @option[:value] : @option)) }
|
9
|
-
raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:regexp))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Validations
|
5
|
-
class SameAsValidator < Base
|
6
|
-
def validate_param!(attr_name, params)
|
7
|
-
confirmation = options_key?(:value) ? @option[:value] : @option
|
8
|
-
return if params[attr_name] == params[confirmation]
|
9
|
-
raise Grape::Exceptions::Validation.new(
|
10
|
-
params: [@scope.full_name(attr_name)],
|
11
|
-
message: build_message
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def build_message
|
18
|
-
if options_key?(:message)
|
19
|
-
@option[:message]
|
20
|
-
else
|
21
|
-
format I18n.t(:same_as, scope: 'grape.errors.messages'), parameter: @option
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|