grape 1.5.3 → 1.7.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 +67 -0
- data/CONTRIBUTING.md +2 -1
- data/README.md +150 -21
- data/UPGRADING.md +61 -4
- data/grape.gemspec +5 -5
- 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 +2 -19
- 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 +8 -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 +20 -35
- data/lib/grape/error_formatter/json.rb +9 -7
- data/lib/grape/error_formatter/xml.rb +2 -6
- data/lib/grape/exceptions/base.rb +2 -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 +2 -2
- 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 +3 -0
- 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/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 +137 -78
- 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/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 +69 -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 +457 -231
- data/spec/grape/config_spec.rb +0 -2
- data/spec/grape/dsl/callbacks_spec.rb +2 -3
- data/spec/grape/dsl/configuration_spec.rb +0 -2
- data/spec/grape/dsl/desc_spec.rb +0 -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 +86 -58
- 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 +61 -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 +0 -2
- 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 +24 -17
- 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 +27 -8
- 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/attributes_iterator_spec.rb +0 -2
- 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 +182 -179
- data/spec/grape/validations_spec.rb +149 -80
- 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 +126 -117
- 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/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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/grape/config.rb
|
116
116
|
- lib/grape/content_types.rb
|
117
117
|
- lib/grape/cookies.rb
|
118
|
+
- lib/grape/dry_types.rb
|
118
119
|
- lib/grape/dsl/api.rb
|
119
120
|
- lib/grape/dsl/callbacks.rb
|
120
121
|
- lib/grape/dsl/configuration.rb
|
@@ -151,6 +152,7 @@ files:
|
|
151
152
|
- lib/grape/exceptions/missing_mime_type.rb
|
152
153
|
- lib/grape/exceptions/missing_option.rb
|
153
154
|
- lib/grape/exceptions/missing_vendor_option.rb
|
155
|
+
- lib/grape/exceptions/too_many_multipart_files.rb
|
154
156
|
- lib/grape/exceptions/unknown_options.rb
|
155
157
|
- lib/grape/exceptions/unknown_parameter.rb
|
156
158
|
- lib/grape/exceptions/unknown_validator.rb
|
@@ -217,6 +219,7 @@ files:
|
|
217
219
|
- lib/grape/util/strict_hash_configuration.rb
|
218
220
|
- lib/grape/util/xml.rb
|
219
221
|
- lib/grape/validations.rb
|
222
|
+
- lib/grape/validations/attributes_doc.rb
|
220
223
|
- lib/grape/validations/attributes_iterator.rb
|
221
224
|
- lib/grape/validations/multiple_attributes_iterator.rb
|
222
225
|
- lib/grape/validations/params_scope.rb
|
@@ -235,25 +238,26 @@ files:
|
|
235
238
|
- lib/grape/validations/types/set_coercer.rb
|
236
239
|
- lib/grape/validations/types/variant_collection_coercer.rb
|
237
240
|
- 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/
|
241
|
+
- lib/grape/validations/validators/all_or_none_of_validator.rb
|
242
|
+
- lib/grape/validations/validators/allow_blank_validator.rb
|
243
|
+
- lib/grape/validations/validators/as_validator.rb
|
244
|
+
- lib/grape/validations/validators/at_least_one_of_validator.rb
|
242
245
|
- 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/
|
246
|
+
- lib/grape/validations/validators/coerce_validator.rb
|
247
|
+
- lib/grape/validations/validators/default_validator.rb
|
248
|
+
- lib/grape/validations/validators/exactly_one_of_validator.rb
|
249
|
+
- lib/grape/validations/validators/except_values_validator.rb
|
247
250
|
- 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/
|
251
|
+
- lib/grape/validations/validators/mutual_exclusion_validator.rb
|
252
|
+
- lib/grape/validations/validators/presence_validator.rb
|
253
|
+
- lib/grape/validations/validators/regexp_validator.rb
|
254
|
+
- lib/grape/validations/validators/same_as_validator.rb
|
255
|
+
- lib/grape/validations/validators/values_validator.rb
|
253
256
|
- lib/grape/version.rb
|
254
257
|
- spec/grape/api/custom_validations_spec.rb
|
255
258
|
- spec/grape/api/deeply_included_options_spec.rb
|
256
259
|
- spec/grape/api/defines_boolean_in_params_spec.rb
|
260
|
+
- spec/grape/api/documentation_spec.rb
|
257
261
|
- spec/grape/api/inherited_helpers_spec.rb
|
258
262
|
- spec/grape/api/instance_spec.rb
|
259
263
|
- spec/grape/api/invalid_format_spec.rb
|
@@ -293,10 +297,12 @@ files:
|
|
293
297
|
- spec/grape/exceptions/invalid_formatter_spec.rb
|
294
298
|
- spec/grape/exceptions/invalid_response_spec.rb
|
295
299
|
- spec/grape/exceptions/invalid_versioner_option_spec.rb
|
300
|
+
- spec/grape/exceptions/missing_group_type_spec.rb
|
296
301
|
- spec/grape/exceptions/missing_mime_type_spec.rb
|
297
302
|
- spec/grape/exceptions/missing_option_spec.rb
|
298
303
|
- spec/grape/exceptions/unknown_options_spec.rb
|
299
304
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
305
|
+
- spec/grape/exceptions/unsupported_group_type_spec.rb
|
300
306
|
- spec/grape/exceptions/validation_errors_spec.rb
|
301
307
|
- spec/grape/exceptions/validation_spec.rb
|
302
308
|
- spec/grape/extensions/param_builders/hash_spec.rb
|
@@ -330,6 +336,7 @@ files:
|
|
330
336
|
- spec/grape/util/reverse_stackable_values_spec.rb
|
331
337
|
- spec/grape/util/stackable_values_spec.rb
|
332
338
|
- spec/grape/util/strict_hash_configuration_spec.rb
|
339
|
+
- spec/grape/validations/attributes_doc_spec.rb
|
333
340
|
- spec/grape/validations/attributes_iterator_spec.rb
|
334
341
|
- spec/grape/validations/instance_behaivour_spec.rb
|
335
342
|
- spec/grape/validations/multiple_attributes_iterator_spec.rb
|
@@ -361,7 +368,6 @@ files:
|
|
361
368
|
- spec/support/basic_auth_encode_helpers.rb
|
362
369
|
- spec/support/chunks.rb
|
363
370
|
- spec/support/content_type_helpers.rb
|
364
|
-
- spec/support/eager_load.rb
|
365
371
|
- spec/support/endpoint_faker.rb
|
366
372
|
- spec/support/file_streamer.rb
|
367
373
|
- spec/support/integer_helpers.rb
|
@@ -371,9 +377,9 @@ licenses:
|
|
371
377
|
- MIT
|
372
378
|
metadata:
|
373
379
|
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.
|
380
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.7.0/CHANGELOG.md
|
381
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/1.7.0
|
382
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.7.0
|
377
383
|
post_install_message:
|
378
384
|
rdoc_options: []
|
379
385
|
require_paths:
|
@@ -382,130 +388,133 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
382
388
|
requirements:
|
383
389
|
- - ">="
|
384
390
|
- !ruby/object:Gem::Version
|
385
|
-
version: 2.
|
391
|
+
version: 2.5.0
|
386
392
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
387
393
|
requirements:
|
388
394
|
- - ">="
|
389
395
|
- !ruby/object:Gem::Version
|
390
396
|
version: '0'
|
391
397
|
requirements: []
|
392
|
-
rubygems_version: 3.
|
398
|
+
rubygems_version: 3.3.7
|
393
399
|
signing_key:
|
394
400
|
specification_version: 4
|
395
401
|
summary: A simple Ruby framework for building REST-like APIs.
|
396
402
|
test_files:
|
397
|
-
- spec/
|
398
|
-
- spec/
|
399
|
-
- spec/
|
400
|
-
- spec/
|
401
|
-
- spec/
|
402
|
-
- spec/
|
403
|
-
- spec/
|
404
|
-
- spec/
|
405
|
-
- spec/
|
406
|
-
- spec/
|
407
|
-
- spec/
|
408
|
-
- spec/
|
409
|
-
- spec/
|
410
|
-
- spec/grape/
|
411
|
-
- spec/grape/
|
412
|
-
- spec/grape/
|
413
|
-
- spec/grape/
|
414
|
-
- spec/grape/
|
415
|
-
- spec/grape/
|
416
|
-
- spec/grape/
|
417
|
-
- spec/grape/middleware/exception_spec.rb
|
418
|
-
- spec/grape/middleware/versioner_spec.rb
|
419
|
-
- spec/grape/middleware/versioner/accept_version_header_spec.rb
|
420
|
-
- spec/grape/middleware/versioner/header_spec.rb
|
421
|
-
- spec/grape/middleware/versioner/path_spec.rb
|
422
|
-
- spec/grape/middleware/versioner/param_spec.rb
|
423
|
-
- spec/grape/middleware/base_spec.rb
|
403
|
+
- spec/grape/api/custom_validations_spec.rb
|
404
|
+
- spec/grape/api/deeply_included_options_spec.rb
|
405
|
+
- spec/grape/api/defines_boolean_in_params_spec.rb
|
406
|
+
- spec/grape/api/documentation_spec.rb
|
407
|
+
- spec/grape/api/inherited_helpers_spec.rb
|
408
|
+
- spec/grape/api/instance_spec.rb
|
409
|
+
- spec/grape/api/invalid_format_spec.rb
|
410
|
+
- spec/grape/api/namespace_parameters_in_route_spec.rb
|
411
|
+
- spec/grape/api/nested_helpers_spec.rb
|
412
|
+
- spec/grape/api/optional_parameters_in_route_spec.rb
|
413
|
+
- spec/grape/api/parameters_modification_spec.rb
|
414
|
+
- spec/grape/api/patch_method_helpers_spec.rb
|
415
|
+
- spec/grape/api/recognize_path_spec.rb
|
416
|
+
- spec/grape/api/required_parameters_in_route_spec.rb
|
417
|
+
- spec/grape/api/required_parameters_with_invalid_method_spec.rb
|
418
|
+
- spec/grape/api/routes_with_requirements_spec.rb
|
419
|
+
- spec/grape/api/shared_helpers_exactly_one_of_spec.rb
|
420
|
+
- spec/grape/api/shared_helpers_spec.rb
|
421
|
+
- spec/grape/api_remount_spec.rb
|
422
|
+
- spec/grape/api_spec.rb
|
424
423
|
- spec/grape/config_spec.rb
|
425
|
-
- spec/grape/
|
424
|
+
- spec/grape/dsl/callbacks_spec.rb
|
425
|
+
- spec/grape/dsl/configuration_spec.rb
|
426
|
+
- spec/grape/dsl/desc_spec.rb
|
427
|
+
- spec/grape/dsl/headers_spec.rb
|
428
|
+
- spec/grape/dsl/helpers_spec.rb
|
429
|
+
- spec/grape/dsl/inside_route_spec.rb
|
430
|
+
- spec/grape/dsl/logger_spec.rb
|
431
|
+
- spec/grape/dsl/middleware_spec.rb
|
432
|
+
- spec/grape/dsl/parameters_spec.rb
|
433
|
+
- spec/grape/dsl/request_response_spec.rb
|
434
|
+
- spec/grape/dsl/routing_spec.rb
|
435
|
+
- spec/grape/dsl/settings_spec.rb
|
436
|
+
- spec/grape/dsl/validations_spec.rb
|
437
|
+
- spec/grape/endpoint/declared_spec.rb
|
426
438
|
- spec/grape/endpoint_spec.rb
|
427
|
-
- spec/grape/api_spec.rb
|
428
|
-
- spec/grape/util/reverse_stackable_values_spec.rb
|
429
|
-
- spec/grape/util/stackable_values_spec.rb
|
430
|
-
- spec/grape/util/inheritable_setting_spec.rb
|
431
|
-
- spec/grape/util/strict_hash_configuration_spec.rb
|
432
|
-
- spec/grape/util/inheritable_values_spec.rb
|
433
|
-
- spec/grape/integration/rack_spec.rb
|
434
|
-
- spec/grape/integration/rack_sendfile_spec.rb
|
435
|
-
- spec/grape/integration/global_namespace_function_spec.rb
|
436
|
-
- spec/grape/validations_spec.rb
|
437
439
|
- spec/grape/entity_spec.rb
|
438
|
-
- spec/grape/exceptions/
|
439
|
-
- spec/grape/exceptions/invalid_accept_header_spec.rb
|
440
|
-
- spec/grape/exceptions/missing_option_spec.rb
|
441
|
-
- spec/grape/exceptions/invalid_response_spec.rb
|
440
|
+
- spec/grape/exceptions/base_spec.rb
|
442
441
|
- spec/grape/exceptions/body_parse_errors_spec.rb
|
442
|
+
- spec/grape/exceptions/invalid_accept_header_spec.rb
|
443
443
|
- spec/grape/exceptions/invalid_formatter_spec.rb
|
444
|
+
- spec/grape/exceptions/invalid_response_spec.rb
|
445
|
+
- spec/grape/exceptions/invalid_versioner_option_spec.rb
|
446
|
+
- spec/grape/exceptions/missing_group_type_spec.rb
|
444
447
|
- spec/grape/exceptions/missing_mime_type_spec.rb
|
448
|
+
- spec/grape/exceptions/missing_option_spec.rb
|
445
449
|
- spec/grape/exceptions/unknown_options_spec.rb
|
446
|
-
- spec/grape/exceptions/validation_errors_spec.rb
|
447
450
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
448
|
-
- spec/grape/exceptions/
|
449
|
-
- spec/grape/exceptions/
|
451
|
+
- spec/grape/exceptions/unsupported_group_type_spec.rb
|
452
|
+
- spec/grape/exceptions/validation_errors_spec.rb
|
453
|
+
- spec/grape/exceptions/validation_spec.rb
|
454
|
+
- spec/grape/extensions/param_builders/hash_spec.rb
|
455
|
+
- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
|
456
|
+
- spec/grape/extensions/param_builders/hashie/mash_spec.rb
|
457
|
+
- spec/grape/integration/global_namespace_function_spec.rb
|
458
|
+
- spec/grape/integration/rack_sendfile_spec.rb
|
459
|
+
- spec/grape/integration/rack_spec.rb
|
460
|
+
- spec/grape/loading_spec.rb
|
461
|
+
- spec/grape/middleware/auth/base_spec.rb
|
462
|
+
- spec/grape/middleware/auth/dsl_spec.rb
|
463
|
+
- spec/grape/middleware/auth/strategies_spec.rb
|
464
|
+
- spec/grape/middleware/base_spec.rb
|
465
|
+
- spec/grape/middleware/error_spec.rb
|
466
|
+
- spec/grape/middleware/exception_spec.rb
|
467
|
+
- spec/grape/middleware/formatter_spec.rb
|
468
|
+
- spec/grape/middleware/globals_spec.rb
|
469
|
+
- spec/grape/middleware/stack_spec.rb
|
470
|
+
- spec/grape/middleware/versioner/accept_version_header_spec.rb
|
471
|
+
- spec/grape/middleware/versioner/header_spec.rb
|
472
|
+
- spec/grape/middleware/versioner/param_spec.rb
|
473
|
+
- spec/grape/middleware/versioner/path_spec.rb
|
474
|
+
- spec/grape/middleware/versioner_spec.rb
|
475
|
+
- spec/grape/named_api_spec.rb
|
476
|
+
- spec/grape/parser_spec.rb
|
477
|
+
- spec/grape/path_spec.rb
|
450
478
|
- spec/grape/presenters/presenter_spec.rb
|
451
|
-
- spec/grape/
|
479
|
+
- spec/grape/request_spec.rb
|
480
|
+
- spec/grape/util/inheritable_setting_spec.rb
|
481
|
+
- spec/grape/util/inheritable_values_spec.rb
|
482
|
+
- spec/grape/util/reverse_stackable_values_spec.rb
|
483
|
+
- spec/grape/util/stackable_values_spec.rb
|
484
|
+
- spec/grape/util/strict_hash_configuration_spec.rb
|
485
|
+
- spec/grape/validations/attributes_doc_spec.rb
|
452
486
|
- spec/grape/validations/attributes_iterator_spec.rb
|
453
|
-
- spec/grape/validations/types/primitive_coercer_spec.rb
|
454
|
-
- spec/grape/validations/types/set_coercer_spec.rb
|
455
|
-
- spec/grape/validations/types/array_coercer_spec.rb
|
456
|
-
- spec/grape/validations/params_scope_spec.rb
|
457
487
|
- spec/grape/validations/instance_behaivour_spec.rb
|
458
488
|
- spec/grape/validations/multiple_attributes_iterator_spec.rb
|
489
|
+
- spec/grape/validations/params_scope_spec.rb
|
490
|
+
- spec/grape/validations/single_attribute_iterator_spec.rb
|
491
|
+
- spec/grape/validations/types/array_coercer_spec.rb
|
492
|
+
- spec/grape/validations/types/primitive_coercer_spec.rb
|
493
|
+
- spec/grape/validations/types/set_coercer_spec.rb
|
459
494
|
- spec/grape/validations/types_spec.rb
|
460
|
-
- spec/grape/validations/validators/
|
461
|
-
- spec/grape/validations/validators/
|
495
|
+
- spec/grape/validations/validators/all_or_none_spec.rb
|
496
|
+
- spec/grape/validations/validators/allow_blank_spec.rb
|
497
|
+
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
498
|
+
- spec/grape/validations/validators/coerce_spec.rb
|
499
|
+
- spec/grape/validations/validators/default_spec.rb
|
462
500
|
- spec/grape/validations/validators/exactly_one_of_spec.rb
|
463
501
|
- spec/grape/validations/validators/except_values_spec.rb
|
502
|
+
- spec/grape/validations/validators/mutual_exclusion_spec.rb
|
464
503
|
- spec/grape/validations/validators/presence_spec.rb
|
465
|
-
- spec/grape/validations/validators/
|
466
|
-
- spec/grape/validations/validators/allow_blank_spec.rb
|
504
|
+
- spec/grape/validations/validators/regexp_spec.rb
|
467
505
|
- spec/grape/validations/validators/same_as_spec.rb
|
468
|
-
- spec/grape/validations/validators/default_spec.rb
|
469
506
|
- spec/grape/validations/validators/values_spec.rb
|
470
|
-
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
471
|
-
- spec/grape/validations/validators/coerce_spec.rb
|
472
507
|
- spec/grape/validations/validators/zh-CN.yml
|
473
|
-
- spec/grape/
|
474
|
-
- spec/
|
475
|
-
- spec/
|
476
|
-
- spec/
|
477
|
-
- spec/
|
478
|
-
- spec/
|
479
|
-
- spec/
|
480
|
-
- spec/
|
481
|
-
- spec/
|
482
|
-
- spec/
|
483
|
-
- spec/
|
484
|
-
- spec/
|
485
|
-
- spec/
|
486
|
-
- spec/grape/api/instance_spec.rb
|
487
|
-
- spec/grape/api/namespace_parameters_in_route_spec.rb
|
488
|
-
- spec/grape/api/recognize_path_spec.rb
|
489
|
-
- spec/grape/api/shared_helpers_exactly_one_of_spec.rb
|
490
|
-
- spec/grape/api/inherited_helpers_spec.rb
|
491
|
-
- spec/grape/api/shared_helpers_spec.rb
|
492
|
-
- spec/grape/api/deeply_included_options_spec.rb
|
493
|
-
- spec/grape/api/routes_with_requirements_spec.rb
|
494
|
-
- spec/grape/api/custom_validations_spec.rb
|
495
|
-
- spec/grape/api/optional_parameters_in_route_spec.rb
|
496
|
-
- spec/grape/api_remount_spec.rb
|
497
|
-
- spec/grape/named_api_spec.rb
|
498
|
-
- spec/grape/dsl/request_response_spec.rb
|
499
|
-
- spec/grape/dsl/desc_spec.rb
|
500
|
-
- spec/grape/dsl/logger_spec.rb
|
501
|
-
- spec/grape/dsl/configuration_spec.rb
|
502
|
-
- spec/grape/dsl/validations_spec.rb
|
503
|
-
- spec/grape/dsl/parameters_spec.rb
|
504
|
-
- spec/grape/dsl/helpers_spec.rb
|
505
|
-
- spec/grape/dsl/middleware_spec.rb
|
506
|
-
- spec/grape/dsl/headers_spec.rb
|
507
|
-
- spec/grape/dsl/callbacks_spec.rb
|
508
|
-
- spec/grape/dsl/settings_spec.rb
|
509
|
-
- spec/grape/dsl/routing_spec.rb
|
510
|
-
- spec/grape/dsl/inside_route_spec.rb
|
511
|
-
- spec/grape/path_spec.rb
|
508
|
+
- spec/grape/validations_spec.rb
|
509
|
+
- spec/integration/eager_load/eager_load_spec.rb
|
510
|
+
- spec/integration/multi_json/json_spec.rb
|
511
|
+
- spec/integration/multi_xml/xml_spec.rb
|
512
|
+
- spec/shared/versioning_examples.rb
|
513
|
+
- spec/spec_helper.rb
|
514
|
+
- spec/support/basic_auth_encode_helpers.rb
|
515
|
+
- spec/support/chunks.rb
|
516
|
+
- spec/support/content_type_helpers.rb
|
517
|
+
- spec/support/endpoint_faker.rb
|
518
|
+
- spec/support/file_streamer.rb
|
519
|
+
- spec/support/integer_helpers.rb
|
520
|
+
- spec/support/versioned_helpers.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
|