grape 1.5.1 → 1.6.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 +57 -3
- data/CONTRIBUTING.md +1 -0
- data/README.md +50 -8
- data/UPGRADING.md +69 -0
- data/grape.gemspec +5 -5
- data/lib/grape/api/instance.rb +13 -17
- data/lib/grape/api.rb +19 -14
- data/lib/grape/cookies.rb +2 -0
- data/lib/grape/dry_types.rb +12 -0
- data/lib/grape/dsl/callbacks.rb +1 -1
- data/lib/grape/dsl/desc.rb +3 -5
- data/lib/grape/dsl/headers.rb +5 -2
- data/lib/grape/dsl/helpers.rb +7 -5
- data/lib/grape/dsl/inside_route.rb +18 -9
- data/lib/grape/dsl/middleware.rb +4 -4
- data/lib/grape/dsl/parameters.rb +4 -4
- data/lib/grape/dsl/request_response.rb +9 -6
- data/lib/grape/dsl/routing.rb +7 -6
- data/lib/grape/dsl/settings.rb +5 -5
- data/lib/grape/endpoint.rb +21 -36
- data/lib/grape/error_formatter/json.rb +2 -6
- data/lib/grape/error_formatter/xml.rb +2 -6
- data/lib/grape/exceptions/empty_message_body.rb +11 -0
- data/lib/grape/exceptions/validation.rb +2 -3
- data/lib/grape/exceptions/validation_errors.rb +1 -1
- 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 +1 -1
- data/lib/grape/middleware/auth/base.rb +3 -3
- data/lib/grape/middleware/auth/dsl.rb +7 -1
- data/lib/grape/middleware/base.rb +5 -3
- data/lib/grape/middleware/error.rb +1 -1
- data/lib/grape/middleware/formatter.rb +4 -4
- data/lib/grape/middleware/stack.rb +14 -20
- 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/parser/json.rb +1 -1
- data/lib/grape/parser/xml.rb +1 -1
- 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/params_scope.rb +89 -56
- data/lib/grape/validations/types/array_coercer.rb +0 -2
- data/lib/grape/validations/types/custom_type_coercer.rb +3 -2
- data/lib/grape/validations/types/dry_type_coercer.rb +2 -11
- data/lib/grape/validations/types/invalid_value.rb +24 -0
- data/lib/grape/validations/types/json.rb +2 -3
- data/lib/grape/validations/types/primitive_coercer.rb +5 -7
- data/lib/grape/validations/types/set_coercer.rb +0 -3
- data/lib/grape/validations/types.rb +83 -12
- 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 +75 -69
- 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/version.rb +1 -1
- data/lib/grape.rb +61 -24
- data/spec/grape/api/custom_validations_spec.rb +77 -45
- data/spec/grape/api/deeply_included_options_spec.rb +3 -3
- data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -1
- data/spec/grape/api/invalid_format_spec.rb +2 -0
- data/spec/grape/api/recognize_path_spec.rb +1 -1
- data/spec/grape/api/routes_with_requirements_spec.rb +8 -8
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -15
- data/spec/grape/api_remount_spec.rb +25 -19
- data/spec/grape/api_spec.rb +510 -220
- data/spec/grape/dsl/callbacks_spec.rb +2 -1
- data/spec/grape/dsl/headers_spec.rb +39 -9
- data/spec/grape/dsl/helpers_spec.rb +3 -2
- data/spec/grape/dsl/inside_route_spec.rb +6 -4
- data/spec/grape/dsl/logger_spec.rb +16 -18
- data/spec/grape/dsl/middleware_spec.rb +2 -1
- data/spec/grape/dsl/parameters_spec.rb +2 -0
- data/spec/grape/dsl/request_response_spec.rb +1 -0
- data/spec/grape/dsl/routing_spec.rb +10 -7
- data/spec/grape/endpoint/declared_spec.rb +259 -12
- data/spec/grape/endpoint_spec.rb +77 -55
- data/spec/grape/entity_spec.rb +23 -23
- data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -0
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -22
- data/spec/grape/exceptions/validation_errors_spec.rb +13 -10
- data/spec/grape/exceptions/validation_spec.rb +5 -3
- data/spec/grape/extensions/param_builders/hash_spec.rb +7 -7
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -8
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -8
- data/spec/grape/integration/rack_sendfile_spec.rb +1 -1
- data/spec/grape/loading_spec.rb +8 -8
- data/spec/grape/middleware/auth/dsl_spec.rb +15 -6
- data/spec/grape/middleware/auth/strategies_spec.rb +60 -20
- data/spec/grape/middleware/base_spec.rb +24 -15
- data/spec/grape/middleware/error_spec.rb +2 -2
- data/spec/grape/middleware/exception_spec.rb +111 -161
- data/spec/grape/middleware/formatter_spec.rb +27 -6
- data/spec/grape/middleware/globals_spec.rb +7 -4
- data/spec/grape/middleware/stack_spec.rb +15 -14
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -1
- data/spec/grape/middleware/versioner/header_spec.rb +14 -13
- data/spec/grape/middleware/versioner/param_spec.rb +7 -1
- data/spec/grape/middleware/versioner/path_spec.rb +5 -1
- data/spec/grape/middleware/versioner_spec.rb +1 -1
- data/spec/grape/parser_spec.rb +4 -0
- data/spec/grape/path_spec.rb +52 -52
- data/spec/grape/presenters/presenter_spec.rb +7 -6
- data/spec/grape/request_spec.rb +6 -4
- data/spec/grape/util/inheritable_setting_spec.rb +7 -7
- data/spec/grape/util/inheritable_values_spec.rb +3 -2
- data/spec/grape/util/reverse_stackable_values_spec.rb +3 -1
- data/spec/grape/util/stackable_values_spec.rb +7 -5
- data/spec/grape/validations/instance_behaivour_spec.rb +9 -10
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +1 -0
- data/spec/grape/validations/params_scope_spec.rb +46 -10
- data/spec/grape/validations/single_attribute_iterator_spec.rb +2 -1
- data/spec/grape/validations/types/primitive_coercer_spec.rb +4 -4
- data/spec/grape/validations/types_spec.rb +8 -8
- data/spec/grape/validations/validators/all_or_none_spec.rb +50 -56
- data/spec/grape/validations/validators/allow_blank_spec.rb +136 -140
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -56
- data/spec/grape/validations/validators/coerce_spec.rb +139 -34
- data/spec/grape/validations/validators/default_spec.rb +72 -78
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
- data/spec/grape/validations/validators/except_values_spec.rb +3 -3
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -77
- data/spec/grape/validations/validators/presence_spec.rb +16 -1
- data/spec/grape/validations/validators/regexp_spec.rb +25 -31
- data/spec/grape/validations/validators/same_as_spec.rb +14 -20
- data/spec/grape/validations/validators/values_spec.rb +183 -178
- data/spec/grape/validations_spec.rb +99 -58
- data/spec/integration/eager_load/eager_load_spec.rb +2 -2
- data/spec/integration/multi_json/json_spec.rb +1 -1
- data/spec/integration/multi_xml/xml_spec.rb +1 -1
- data/spec/shared/versioning_examples.rb +32 -29
- data/spec/spec_helper.rb +12 -2
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- data/spec/support/versioned_helpers.rb +1 -1
- metadata +117 -115
- data/lib/grape/validations/types/build_coercer.rb +0 -94
- 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 -88
- 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
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.6.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: 2021-12-28 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
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- lib/grape/error_formatter/txt.rb
|
138
139
|
- lib/grape/error_formatter/xml.rb
|
139
140
|
- lib/grape/exceptions/base.rb
|
141
|
+
- lib/grape/exceptions/empty_message_body.rb
|
140
142
|
- lib/grape/exceptions/incompatible_option_values.rb
|
141
143
|
- lib/grape/exceptions/invalid_accept_header.rb
|
142
144
|
- lib/grape/exceptions/invalid_formatter.rb
|
@@ -222,32 +224,32 @@ files:
|
|
222
224
|
- lib/grape/validations/single_attribute_iterator.rb
|
223
225
|
- lib/grape/validations/types.rb
|
224
226
|
- lib/grape/validations/types/array_coercer.rb
|
225
|
-
- lib/grape/validations/types/build_coercer.rb
|
226
227
|
- lib/grape/validations/types/custom_type_coercer.rb
|
227
228
|
- lib/grape/validations/types/custom_type_collection_coercer.rb
|
228
229
|
- lib/grape/validations/types/dry_type_coercer.rb
|
229
230
|
- lib/grape/validations/types/file.rb
|
231
|
+
- lib/grape/validations/types/invalid_value.rb
|
230
232
|
- lib/grape/validations/types/json.rb
|
231
233
|
- lib/grape/validations/types/multiple_type_coercer.rb
|
232
234
|
- lib/grape/validations/types/primitive_coercer.rb
|
233
235
|
- lib/grape/validations/types/set_coercer.rb
|
234
236
|
- lib/grape/validations/types/variant_collection_coercer.rb
|
235
237
|
- lib/grape/validations/validator_factory.rb
|
236
|
-
- lib/grape/validations/validators/
|
237
|
-
- lib/grape/validations/validators/
|
238
|
-
- lib/grape/validations/validators/
|
239
|
-
- lib/grape/validations/validators/
|
238
|
+
- lib/grape/validations/validators/all_or_none_of_validator.rb
|
239
|
+
- lib/grape/validations/validators/allow_blank_validator.rb
|
240
|
+
- lib/grape/validations/validators/as_validator.rb
|
241
|
+
- lib/grape/validations/validators/at_least_one_of_validator.rb
|
240
242
|
- lib/grape/validations/validators/base.rb
|
241
|
-
- lib/grape/validations/validators/
|
242
|
-
- lib/grape/validations/validators/
|
243
|
-
- lib/grape/validations/validators/
|
244
|
-
- lib/grape/validations/validators/
|
243
|
+
- lib/grape/validations/validators/coerce_validator.rb
|
244
|
+
- lib/grape/validations/validators/default_validator.rb
|
245
|
+
- lib/grape/validations/validators/exactly_one_of_validator.rb
|
246
|
+
- lib/grape/validations/validators/except_values_validator.rb
|
245
247
|
- lib/grape/validations/validators/multiple_params_base.rb
|
246
|
-
- lib/grape/validations/validators/
|
247
|
-
- lib/grape/validations/validators/
|
248
|
-
- lib/grape/validations/validators/
|
249
|
-
- lib/grape/validations/validators/
|
250
|
-
- lib/grape/validations/validators/
|
248
|
+
- lib/grape/validations/validators/mutual_exclusion_validator.rb
|
249
|
+
- lib/grape/validations/validators/presence_validator.rb
|
250
|
+
- lib/grape/validations/validators/regexp_validator.rb
|
251
|
+
- lib/grape/validations/validators/same_as_validator.rb
|
252
|
+
- lib/grape/validations/validators/values_validator.rb
|
251
253
|
- lib/grape/version.rb
|
252
254
|
- spec/grape/api/custom_validations_spec.rb
|
253
255
|
- spec/grape/api/deeply_included_options_spec.rb
|
@@ -369,10 +371,10 @@ licenses:
|
|
369
371
|
- MIT
|
370
372
|
metadata:
|
371
373
|
bug_tracker_uri: https://github.com/ruby-grape/grape/issues
|
372
|
-
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.
|
373
|
-
documentation_uri: https://www.rubydoc.info/gems/grape/1.
|
374
|
-
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.
|
375
|
-
post_install_message:
|
374
|
+
changelog_uri: https://github.com/ruby-grape/grape/blob/v1.6.1/CHANGELOG.md
|
375
|
+
documentation_uri: https://www.rubydoc.info/gems/grape/1.6.1
|
376
|
+
source_code_uri: https://github.com/ruby-grape/grape/tree/v1.6.1
|
377
|
+
post_install_message:
|
376
378
|
rdoc_options: []
|
377
379
|
require_paths:
|
378
380
|
- lib
|
@@ -380,130 +382,130 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
380
382
|
requirements:
|
381
383
|
- - ">="
|
382
384
|
- !ruby/object:Gem::Version
|
383
|
-
version: 2.
|
385
|
+
version: 2.5.0
|
384
386
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
385
387
|
requirements:
|
386
388
|
- - ">="
|
387
389
|
- !ruby/object:Gem::Version
|
388
390
|
version: '0'
|
389
391
|
requirements: []
|
390
|
-
rubygems_version: 3.0.
|
391
|
-
signing_key:
|
392
|
+
rubygems_version: 3.3.0.dev
|
393
|
+
signing_key:
|
392
394
|
specification_version: 4
|
393
395
|
summary: A simple Ruby framework for building REST-like APIs.
|
394
396
|
test_files:
|
395
|
-
- spec/shared/versioning_examples.rb
|
396
|
-
- spec/support/versioned_helpers.rb
|
397
|
-
- spec/support/content_type_helpers.rb
|
398
|
-
- spec/support/eager_load.rb
|
399
|
-
- spec/support/basic_auth_encode_helpers.rb
|
400
|
-
- spec/support/file_streamer.rb
|
401
|
-
- spec/support/chunks.rb
|
402
|
-
- spec/support/endpoint_faker.rb
|
403
|
-
- spec/support/integer_helpers.rb
|
404
|
-
- spec/grape/api/namespace_parameters_in_route_spec.rb
|
405
|
-
- spec/grape/api/routes_with_requirements_spec.rb
|
406
|
-
- spec/grape/api/nested_helpers_spec.rb
|
407
|
-
- spec/grape/api/required_parameters_in_route_spec.rb
|
408
|
-
- spec/grape/api/shared_helpers_exactly_one_of_spec.rb
|
409
|
-
- spec/grape/api/parameters_modification_spec.rb
|
410
|
-
- spec/grape/api/optional_parameters_in_route_spec.rb
|
411
|
-
- spec/grape/api/inherited_helpers_spec.rb
|
412
|
-
- spec/grape/api/required_parameters_with_invalid_method_spec.rb
|
413
397
|
- spec/grape/api/custom_validations_spec.rb
|
414
|
-
- spec/grape/api/defines_boolean_in_params_spec.rb
|
415
|
-
- spec/grape/api/shared_helpers_spec.rb
|
416
|
-
- spec/grape/api/invalid_format_spec.rb
|
417
398
|
- spec/grape/api/deeply_included_options_spec.rb
|
399
|
+
- spec/grape/api/defines_boolean_in_params_spec.rb
|
400
|
+
- spec/grape/api/inherited_helpers_spec.rb
|
418
401
|
- spec/grape/api/instance_spec.rb
|
402
|
+
- spec/grape/api/invalid_format_spec.rb
|
403
|
+
- spec/grape/api/namespace_parameters_in_route_spec.rb
|
404
|
+
- spec/grape/api/nested_helpers_spec.rb
|
405
|
+
- spec/grape/api/optional_parameters_in_route_spec.rb
|
406
|
+
- spec/grape/api/parameters_modification_spec.rb
|
419
407
|
- spec/grape/api/patch_method_helpers_spec.rb
|
420
408
|
- spec/grape/api/recognize_path_spec.rb
|
409
|
+
- spec/grape/api/required_parameters_in_route_spec.rb
|
410
|
+
- spec/grape/api/required_parameters_with_invalid_method_spec.rb
|
411
|
+
- spec/grape/api/routes_with_requirements_spec.rb
|
412
|
+
- spec/grape/api/shared_helpers_exactly_one_of_spec.rb
|
413
|
+
- spec/grape/api/shared_helpers_spec.rb
|
421
414
|
- spec/grape/api_remount_spec.rb
|
422
|
-
- spec/grape/
|
423
|
-
- spec/grape/validations/attributes_iterator_spec.rb
|
424
|
-
- spec/grape/validations/types/array_coercer_spec.rb
|
425
|
-
- spec/grape/validations/types/set_coercer_spec.rb
|
426
|
-
- spec/grape/validations/types/primitive_coercer_spec.rb
|
427
|
-
- spec/grape/validations/validators/regexp_spec.rb
|
428
|
-
- spec/grape/validations/validators/default_spec.rb
|
429
|
-
- spec/grape/validations/validators/values_spec.rb
|
430
|
-
- spec/grape/validations/validators/same_as_spec.rb
|
431
|
-
- spec/grape/validations/validators/mutual_exclusion_spec.rb
|
432
|
-
- spec/grape/validations/validators/except_values_spec.rb
|
433
|
-
- spec/grape/validations/validators/exactly_one_of_spec.rb
|
434
|
-
- spec/grape/validations/validators/allow_blank_spec.rb
|
435
|
-
- spec/grape/validations/validators/coerce_spec.rb
|
436
|
-
- spec/grape/validations/validators/presence_spec.rb
|
437
|
-
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
438
|
-
- spec/grape/validations/validators/zh-CN.yml
|
439
|
-
- spec/grape/validations/validators/all_or_none_spec.rb
|
440
|
-
- spec/grape/validations/params_scope_spec.rb
|
441
|
-
- spec/grape/validations/multiple_attributes_iterator_spec.rb
|
442
|
-
- spec/grape/validations/instance_behaivour_spec.rb
|
443
|
-
- spec/grape/validations/single_attribute_iterator_spec.rb
|
415
|
+
- spec/grape/api_spec.rb
|
444
416
|
- spec/grape/config_spec.rb
|
445
|
-
- spec/grape/
|
417
|
+
- spec/grape/dsl/callbacks_spec.rb
|
418
|
+
- spec/grape/dsl/configuration_spec.rb
|
419
|
+
- spec/grape/dsl/desc_spec.rb
|
420
|
+
- spec/grape/dsl/headers_spec.rb
|
421
|
+
- spec/grape/dsl/helpers_spec.rb
|
422
|
+
- spec/grape/dsl/inside_route_spec.rb
|
423
|
+
- spec/grape/dsl/logger_spec.rb
|
424
|
+
- spec/grape/dsl/middleware_spec.rb
|
425
|
+
- spec/grape/dsl/parameters_spec.rb
|
426
|
+
- spec/grape/dsl/request_response_spec.rb
|
427
|
+
- spec/grape/dsl/routing_spec.rb
|
428
|
+
- spec/grape/dsl/settings_spec.rb
|
429
|
+
- spec/grape/dsl/validations_spec.rb
|
430
|
+
- spec/grape/endpoint/declared_spec.rb
|
431
|
+
- spec/grape/endpoint_spec.rb
|
432
|
+
- spec/grape/entity_spec.rb
|
433
|
+
- spec/grape/exceptions/base_spec.rb
|
446
434
|
- spec/grape/exceptions/body_parse_errors_spec.rb
|
447
|
-
- spec/grape/exceptions/missing_option_spec.rb
|
448
435
|
- spec/grape/exceptions/invalid_accept_header_spec.rb
|
449
|
-
- spec/grape/exceptions/validation_spec.rb
|
450
|
-
- spec/grape/exceptions/unknown_validator_spec.rb
|
451
|
-
- spec/grape/exceptions/validation_errors_spec.rb
|
452
|
-
- spec/grape/exceptions/invalid_response_spec.rb
|
453
|
-
- spec/grape/exceptions/unknown_options_spec.rb
|
454
436
|
- spec/grape/exceptions/invalid_formatter_spec.rb
|
437
|
+
- spec/grape/exceptions/invalid_response_spec.rb
|
455
438
|
- spec/grape/exceptions/invalid_versioner_option_spec.rb
|
456
439
|
- spec/grape/exceptions/missing_mime_type_spec.rb
|
457
|
-
- spec/grape/exceptions/
|
458
|
-
- spec/grape/
|
459
|
-
- spec/grape/
|
460
|
-
- spec/grape/
|
461
|
-
- spec/grape/
|
462
|
-
- spec/grape/util/reverse_stackable_values_spec.rb
|
463
|
-
- spec/grape/util/inheritable_values_spec.rb
|
464
|
-
- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
|
440
|
+
- spec/grape/exceptions/missing_option_spec.rb
|
441
|
+
- spec/grape/exceptions/unknown_options_spec.rb
|
442
|
+
- spec/grape/exceptions/unknown_validator_spec.rb
|
443
|
+
- spec/grape/exceptions/validation_errors_spec.rb
|
444
|
+
- spec/grape/exceptions/validation_spec.rb
|
465
445
|
- spec/grape/extensions/param_builders/hash_spec.rb
|
446
|
+
- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
|
466
447
|
- spec/grape/extensions/param_builders/hashie/mash_spec.rb
|
467
|
-
- spec/grape/integration/rack_spec.rb
|
468
|
-
- spec/grape/integration/rack_sendfile_spec.rb
|
469
448
|
- spec/grape/integration/global_namespace_function_spec.rb
|
470
|
-
- spec/grape/
|
471
|
-
- spec/grape/
|
472
|
-
- spec/grape/
|
473
|
-
- spec/grape/
|
449
|
+
- spec/grape/integration/rack_sendfile_spec.rb
|
450
|
+
- spec/grape/integration/rack_spec.rb
|
451
|
+
- spec/grape/loading_spec.rb
|
452
|
+
- spec/grape/middleware/auth/base_spec.rb
|
453
|
+
- spec/grape/middleware/auth/dsl_spec.rb
|
454
|
+
- spec/grape/middleware/auth/strategies_spec.rb
|
455
|
+
- spec/grape/middleware/base_spec.rb
|
456
|
+
- spec/grape/middleware/error_spec.rb
|
474
457
|
- spec/grape/middleware/exception_spec.rb
|
475
|
-
- spec/grape/middleware/
|
476
|
-
- spec/grape/middleware/versioner/header_spec.rb
|
477
|
-
- spec/grape/middleware/versioner/path_spec.rb
|
478
|
-
- spec/grape/middleware/versioner/accept_version_header_spec.rb
|
458
|
+
- spec/grape/middleware/formatter_spec.rb
|
479
459
|
- spec/grape/middleware/globals_spec.rb
|
480
460
|
- spec/grape/middleware/stack_spec.rb
|
481
|
-
- spec/grape/middleware/
|
482
|
-
- spec/grape/middleware/
|
483
|
-
- spec/grape/middleware/
|
484
|
-
- spec/grape/middleware/
|
485
|
-
- spec/grape/middleware/auth/base_spec.rb
|
461
|
+
- spec/grape/middleware/versioner/accept_version_header_spec.rb
|
462
|
+
- spec/grape/middleware/versioner/header_spec.rb
|
463
|
+
- spec/grape/middleware/versioner/param_spec.rb
|
464
|
+
- spec/grape/middleware/versioner/path_spec.rb
|
486
465
|
- spec/grape/middleware/versioner_spec.rb
|
487
|
-
- spec/grape/middleware/base_spec.rb
|
488
|
-
- spec/grape/entity_spec.rb
|
489
|
-
- spec/grape/dsl/settings_spec.rb
|
490
|
-
- spec/grape/dsl/callbacks_spec.rb
|
491
|
-
- spec/grape/dsl/middleware_spec.rb
|
492
|
-
- spec/grape/dsl/inside_route_spec.rb
|
493
|
-
- spec/grape/dsl/configuration_spec.rb
|
494
|
-
- spec/grape/dsl/parameters_spec.rb
|
495
|
-
- spec/grape/dsl/logger_spec.rb
|
496
|
-
- spec/grape/dsl/helpers_spec.rb
|
497
|
-
- spec/grape/dsl/request_response_spec.rb
|
498
|
-
- spec/grape/dsl/routing_spec.rb
|
499
|
-
- spec/grape/dsl/headers_spec.rb
|
500
|
-
- spec/grape/dsl/validations_spec.rb
|
501
|
-
- spec/grape/dsl/desc_spec.rb
|
502
|
-
- spec/grape/validations_spec.rb
|
503
466
|
- spec/grape/named_api_spec.rb
|
504
|
-
- spec/grape/
|
467
|
+
- spec/grape/parser_spec.rb
|
468
|
+
- spec/grape/path_spec.rb
|
469
|
+
- spec/grape/presenters/presenter_spec.rb
|
505
470
|
- spec/grape/request_spec.rb
|
471
|
+
- spec/grape/util/inheritable_setting_spec.rb
|
472
|
+
- spec/grape/util/inheritable_values_spec.rb
|
473
|
+
- spec/grape/util/reverse_stackable_values_spec.rb
|
474
|
+
- spec/grape/util/stackable_values_spec.rb
|
475
|
+
- spec/grape/util/strict_hash_configuration_spec.rb
|
476
|
+
- spec/grape/validations/attributes_iterator_spec.rb
|
477
|
+
- spec/grape/validations/instance_behaivour_spec.rb
|
478
|
+
- spec/grape/validations/multiple_attributes_iterator_spec.rb
|
479
|
+
- spec/grape/validations/params_scope_spec.rb
|
480
|
+
- spec/grape/validations/single_attribute_iterator_spec.rb
|
481
|
+
- spec/grape/validations/types/array_coercer_spec.rb
|
482
|
+
- spec/grape/validations/types/primitive_coercer_spec.rb
|
483
|
+
- spec/grape/validations/types/set_coercer_spec.rb
|
484
|
+
- spec/grape/validations/types_spec.rb
|
485
|
+
- spec/grape/validations/validators/all_or_none_spec.rb
|
486
|
+
- spec/grape/validations/validators/allow_blank_spec.rb
|
487
|
+
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
488
|
+
- spec/grape/validations/validators/coerce_spec.rb
|
489
|
+
- spec/grape/validations/validators/default_spec.rb
|
490
|
+
- spec/grape/validations/validators/exactly_one_of_spec.rb
|
491
|
+
- spec/grape/validations/validators/except_values_spec.rb
|
492
|
+
- spec/grape/validations/validators/mutual_exclusion_spec.rb
|
493
|
+
- spec/grape/validations/validators/presence_spec.rb
|
494
|
+
- spec/grape/validations/validators/regexp_spec.rb
|
495
|
+
- spec/grape/validations/validators/same_as_spec.rb
|
496
|
+
- spec/grape/validations/validators/values_spec.rb
|
497
|
+
- spec/grape/validations/validators/zh-CN.yml
|
498
|
+
- spec/grape/validations_spec.rb
|
506
499
|
- spec/integration/eager_load/eager_load_spec.rb
|
507
|
-
- spec/integration/multi_xml/xml_spec.rb
|
508
500
|
- spec/integration/multi_json/json_spec.rb
|
501
|
+
- spec/integration/multi_xml/xml_spec.rb
|
502
|
+
- spec/shared/versioning_examples.rb
|
509
503
|
- spec/spec_helper.rb
|
504
|
+
- spec/support/basic_auth_encode_helpers.rb
|
505
|
+
- spec/support/chunks.rb
|
506
|
+
- spec/support/content_type_helpers.rb
|
507
|
+
- spec/support/eager_load.rb
|
508
|
+
- spec/support/endpoint_faker.rb
|
509
|
+
- spec/support/file_streamer.rb
|
510
|
+
- spec/support/integer_helpers.rb
|
511
|
+
- spec/support/versioned_helpers.rb
|
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'array_coercer'
|
4
|
-
require_relative 'set_coercer'
|
5
|
-
require_relative 'primitive_coercer'
|
6
|
-
|
7
|
-
module Grape
|
8
|
-
module Validations
|
9
|
-
module Types
|
10
|
-
# Chooses the best coercer for the given type. For example, if the type
|
11
|
-
# is Integer, it will return a coercer which will be able to coerce a value
|
12
|
-
# to the integer.
|
13
|
-
#
|
14
|
-
# There are a few very special coercers which might be returned.
|
15
|
-
#
|
16
|
-
# +Grape::Types::MultipleTypeCoercer+ is a coercer which is returned when
|
17
|
-
# the given type implies values in an array with different types.
|
18
|
-
# For example, +[Integer, String]+ allows integer and string values in
|
19
|
-
# an array.
|
20
|
-
#
|
21
|
-
# +Grape::Types::CustomTypeCoercer+ is a coercer which is returned when
|
22
|
-
# a method is specified by a user with +coerce_with+ option or the user
|
23
|
-
# specifies a custom type which implements requirments of
|
24
|
-
# +Grape::Types::CustomTypeCoercer+.
|
25
|
-
#
|
26
|
-
# +Grape::Types::CustomTypeCollectionCoercer+ is a very similar to the
|
27
|
-
# previous one, but it expects an array or set of values having a custom
|
28
|
-
# type implemented by the user.
|
29
|
-
#
|
30
|
-
# There is also a group of custom types implemented by Grape, check
|
31
|
-
# +Grape::Validations::Types::SPECIAL+ to get the full list.
|
32
|
-
#
|
33
|
-
# @param type [Class] the type to which input strings
|
34
|
-
# should be coerced
|
35
|
-
# @param method [Class,#call] the coercion method to use
|
36
|
-
# @return [Object] object to be used
|
37
|
-
# for coercion and type validation
|
38
|
-
def self.build_coercer(type, method: nil, strict: false)
|
39
|
-
cache_instance(type, method, strict) do
|
40
|
-
create_coercer_instance(type, method, strict)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.create_coercer_instance(type, method, strict)
|
45
|
-
# Maps a custom type provided by Grape, it doesn't map types wrapped by collections!!!
|
46
|
-
type = Types.map_special(type)
|
47
|
-
|
48
|
-
# Use a special coercer for multiply-typed parameters.
|
49
|
-
if Types.multiple?(type)
|
50
|
-
MultipleTypeCoercer.new(type, method)
|
51
|
-
|
52
|
-
# Use a special coercer for custom types and coercion methods.
|
53
|
-
elsif method || Types.custom?(type)
|
54
|
-
CustomTypeCoercer.new(type, method)
|
55
|
-
|
56
|
-
# Special coercer for collections of types that implement a parse method.
|
57
|
-
# CustomTypeCoercer (above) already handles such types when an explicit coercion
|
58
|
-
# method is supplied.
|
59
|
-
elsif Types.collection_of_custom?(type)
|
60
|
-
Types::CustomTypeCollectionCoercer.new(
|
61
|
-
Types.map_special(type.first), type.is_a?(Set)
|
62
|
-
)
|
63
|
-
else
|
64
|
-
DryTypeCoercer.coercer_instance_for(type, strict)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.cache_instance(type, method, strict, &_block)
|
69
|
-
key = cache_key(type, method, strict)
|
70
|
-
|
71
|
-
return @__cache[key] if @__cache.key?(key)
|
72
|
-
|
73
|
-
instance = yield
|
74
|
-
|
75
|
-
@__cache_write_lock.synchronize do
|
76
|
-
@__cache[key] = instance
|
77
|
-
end
|
78
|
-
|
79
|
-
instance
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.cache_key(type, method, strict)
|
83
|
-
[type, method, strict].each_with_object(+'_') do |val, memo|
|
84
|
-
next if val.nil?
|
85
|
-
|
86
|
-
memo << '_' << val.to_s
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
instance_variable_set(:@__cache, {})
|
91
|
-
instance_variable_set(:@__cache_write_lock, Mutex.new)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
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 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,88 +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(*_args)
|
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) 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)
|
84
|
-
Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:coerce))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
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
|