grape 1.2.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +97 -0
- data/LICENSE +1 -1
- data/README.md +53 -16
- data/UPGRADING.md +231 -23
- data/grape.gemspec +10 -1
- data/lib/grape.rb +6 -7
- data/lib/grape/api.rb +4 -2
- data/lib/grape/api/helpers.rb +2 -0
- data/lib/grape/api/instance.rb +36 -33
- data/lib/grape/config.rb +2 -0
- data/lib/grape/content_types.rb +34 -0
- data/lib/grape/cookies.rb +2 -0
- data/lib/grape/dsl/api.rb +2 -0
- data/lib/grape/dsl/callbacks.rb +2 -0
- data/lib/grape/dsl/configuration.rb +2 -0
- data/lib/grape/dsl/desc.rb +2 -0
- data/lib/grape/dsl/headers.rb +2 -0
- data/lib/grape/dsl/helpers.rb +4 -2
- data/lib/grape/dsl/inside_route.rb +83 -34
- data/lib/grape/dsl/logger.rb +2 -0
- data/lib/grape/dsl/middleware.rb +2 -0
- data/lib/grape/dsl/parameters.rb +8 -6
- data/lib/grape/dsl/request_response.rb +4 -2
- data/lib/grape/dsl/routing.rb +9 -5
- data/lib/grape/dsl/settings.rb +7 -1
- data/lib/grape/dsl/validations.rb +20 -1
- data/lib/grape/eager_load.rb +3 -1
- data/lib/grape/endpoint.rb +21 -13
- data/lib/grape/error_formatter.rb +3 -1
- data/lib/grape/error_formatter/base.rb +2 -0
- data/lib/grape/error_formatter/json.rb +2 -0
- data/lib/grape/error_formatter/txt.rb +2 -0
- data/lib/grape/error_formatter/xml.rb +2 -0
- data/lib/grape/exceptions/base.rb +11 -13
- data/lib/grape/exceptions/incompatible_option_values.rb +2 -0
- data/lib/grape/exceptions/invalid_accept_header.rb +2 -0
- data/lib/grape/exceptions/invalid_formatter.rb +2 -0
- data/lib/grape/exceptions/invalid_message_body.rb +2 -0
- data/lib/grape/exceptions/invalid_response.rb +2 -0
- data/lib/grape/exceptions/invalid_version_header.rb +2 -0
- data/lib/grape/exceptions/invalid_versioner_option.rb +2 -0
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +2 -0
- data/lib/grape/exceptions/method_not_allowed.rb +2 -0
- data/lib/grape/exceptions/missing_group_type.rb +2 -0
- data/lib/grape/exceptions/missing_mime_type.rb +2 -0
- data/lib/grape/exceptions/missing_option.rb +2 -0
- data/lib/grape/exceptions/missing_vendor_option.rb +2 -0
- data/lib/grape/exceptions/unknown_options.rb +2 -0
- data/lib/grape/exceptions/unknown_parameter.rb +2 -0
- data/lib/grape/exceptions/unknown_validator.rb +2 -0
- data/lib/grape/exceptions/unsupported_group_type.rb +2 -0
- data/lib/grape/exceptions/validation.rb +3 -1
- data/lib/grape/exceptions/validation_array_errors.rb +2 -0
- data/lib/grape/exceptions/validation_errors.rb +13 -12
- data/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +4 -3
- data/lib/grape/extensions/deep_mergeable_hash.rb +2 -0
- data/lib/grape/extensions/deep_symbolize_hash.rb +2 -0
- data/lib/grape/extensions/hash.rb +2 -0
- data/lib/grape/extensions/hashie/mash.rb +2 -0
- data/lib/grape/formatter.rb +5 -3
- data/lib/grape/formatter/json.rb +2 -0
- data/lib/grape/formatter/serializable_hash.rb +2 -0
- data/lib/grape/formatter/txt.rb +2 -0
- data/lib/grape/formatter/xml.rb +2 -0
- data/lib/grape/http/headers.rb +50 -18
- data/lib/grape/middleware/auth/base.rb +2 -0
- data/lib/grape/middleware/auth/dsl.rb +2 -0
- data/lib/grape/middleware/auth/strategies.rb +2 -0
- data/lib/grape/middleware/auth/strategy_info.rb +2 -0
- data/lib/grape/middleware/base.rb +7 -7
- data/lib/grape/middleware/error.rb +3 -1
- data/lib/grape/middleware/filter.rb +2 -0
- data/lib/grape/middleware/formatter.rb +8 -6
- data/lib/grape/middleware/globals.rb +2 -0
- data/lib/grape/middleware/helpers.rb +2 -0
- data/lib/grape/middleware/stack.rb +4 -1
- data/lib/grape/middleware/versioner.rb +2 -0
- data/lib/grape/middleware/versioner/accept_version_header.rb +2 -0
- data/lib/grape/middleware/versioner/header.rb +6 -4
- data/lib/grape/middleware/versioner/param.rb +3 -1
- data/lib/grape/middleware/versioner/parse_media_type_patch.rb +4 -1
- data/lib/grape/middleware/versioner/path.rb +3 -1
- data/lib/grape/namespace.rb +14 -2
- data/lib/grape/parser.rb +3 -1
- data/lib/grape/parser/json.rb +2 -0
- data/lib/grape/parser/xml.rb +2 -0
- data/lib/grape/path.rb +15 -3
- data/lib/grape/presenters/presenter.rb +2 -0
- data/lib/grape/request.rb +15 -8
- data/lib/grape/router.rb +30 -29
- data/lib/grape/router/attribute_translator.rb +39 -8
- data/lib/grape/router/pattern.rb +20 -16
- data/lib/grape/router/route.rb +12 -26
- data/lib/grape/{serve_file → serve_stream}/file_body.rb +3 -1
- data/lib/grape/{serve_file → serve_stream}/sendfile_response.rb +3 -1
- data/lib/grape/{serve_file/file_response.rb → serve_stream/stream_response.rb} +10 -8
- data/lib/grape/util/base_inheritable.rb +15 -6
- data/lib/grape/util/cache.rb +20 -0
- data/lib/grape/util/endpoint_configuration.rb +2 -0
- data/lib/grape/util/env.rb +19 -17
- data/lib/grape/util/inheritable_setting.rb +2 -0
- data/lib/grape/util/inheritable_values.rb +2 -0
- data/lib/grape/util/json.rb +2 -0
- data/lib/grape/util/lazy_block.rb +2 -0
- data/lib/grape/util/lazy_object.rb +43 -0
- data/lib/grape/util/lazy_value.rb +2 -0
- data/lib/grape/util/registrable.rb +2 -0
- data/lib/grape/util/reverse_stackable_values.rb +4 -0
- data/lib/grape/util/stackable_values.rb +10 -20
- data/lib/grape/util/strict_hash_configuration.rb +2 -0
- data/lib/grape/util/xml.rb +2 -0
- data/lib/grape/validations.rb +2 -0
- data/lib/grape/validations/attributes_iterator.rb +3 -3
- data/lib/grape/validations/multiple_attributes_iterator.rb +2 -0
- data/lib/grape/validations/params_scope.rb +27 -14
- data/lib/grape/validations/single_attribute_iterator.rb +13 -2
- data/lib/grape/validations/types.rb +12 -34
- data/lib/grape/validations/types/array_coercer.rb +65 -0
- data/lib/grape/validations/types/build_coercer.rb +47 -49
- data/lib/grape/validations/types/custom_type_coercer.rb +15 -49
- data/lib/grape/validations/types/custom_type_collection_coercer.rb +10 -25
- data/lib/grape/validations/types/dry_type_coercer.rb +76 -0
- data/lib/grape/validations/types/file.rb +22 -18
- data/lib/grape/validations/types/json.rb +46 -39
- data/lib/grape/validations/types/multiple_type_coercer.rb +14 -33
- data/lib/grape/validations/types/primitive_coercer.rb +67 -0
- data/lib/grape/validations/types/set_coercer.rb +40 -0
- data/lib/grape/validations/types/variant_collection_coercer.rb +5 -13
- data/lib/grape/validations/validator_factory.rb +2 -0
- data/lib/grape/validations/validators/all_or_none.rb +3 -1
- data/lib/grape/validations/validators/allow_blank.rb +3 -1
- data/lib/grape/validations/validators/as.rb +2 -0
- data/lib/grape/validations/validators/at_least_one_of.rb +3 -1
- data/lib/grape/validations/validators/base.rb +8 -5
- data/lib/grape/validations/validators/coerce.rb +39 -29
- data/lib/grape/validations/validators/default.rb +2 -1
- data/lib/grape/validations/validators/exactly_one_of.rb +6 -2
- data/lib/grape/validations/validators/except_values.rb +3 -1
- data/lib/grape/validations/validators/multiple_params_base.rb +2 -0
- data/lib/grape/validations/validators/mutual_exclusion.rb +3 -1
- data/lib/grape/validations/validators/presence.rb +3 -1
- data/lib/grape/validations/validators/regexp.rb +4 -2
- data/lib/grape/validations/validators/same_as.rb +6 -3
- data/lib/grape/validations/validators/values.rb +17 -5
- data/lib/grape/version.rb +3 -1
- data/spec/grape/api/custom_validations_spec.rb +5 -3
- data/spec/grape/api/deeply_included_options_spec.rb +2 -0
- data/spec/grape/api/defines_boolean_in_params_spec.rb +5 -3
- data/spec/grape/api/inherited_helpers_spec.rb +2 -0
- data/spec/grape/api/instance_spec.rb +104 -0
- data/spec/grape/api/invalid_format_spec.rb +2 -0
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +2 -0
- data/spec/grape/api/nested_helpers_spec.rb +2 -0
- data/spec/grape/api/optional_parameters_in_route_spec.rb +2 -0
- data/spec/grape/api/parameters_modification_spec.rb +3 -1
- data/spec/grape/api/patch_method_helpers_spec.rb +2 -0
- data/spec/grape/api/recognize_path_spec.rb +2 -0
- data/spec/grape/api/required_parameters_in_route_spec.rb +2 -0
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +2 -0
- data/spec/grape/api/routes_with_requirements_spec.rb +2 -0
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +2 -0
- data/spec/grape/api/shared_helpers_spec.rb +2 -0
- data/spec/grape/api_remount_spec.rb +2 -0
- data/spec/grape/api_spec.rb +99 -11
- data/spec/grape/config_spec.rb +2 -0
- data/spec/grape/dsl/callbacks_spec.rb +2 -0
- data/spec/grape/dsl/configuration_spec.rb +2 -0
- data/spec/grape/dsl/desc_spec.rb +2 -0
- data/spec/grape/dsl/headers_spec.rb +2 -0
- data/spec/grape/dsl/helpers_spec.rb +4 -2
- data/spec/grape/dsl/inside_route_spec.rb +177 -33
- data/spec/grape/dsl/logger_spec.rb +2 -0
- data/spec/grape/dsl/middleware_spec.rb +2 -0
- data/spec/grape/dsl/parameters_spec.rb +2 -0
- data/spec/grape/dsl/request_response_spec.rb +2 -0
- data/spec/grape/dsl/routing_spec.rb +2 -0
- data/spec/grape/dsl/settings_spec.rb +2 -0
- data/spec/grape/dsl/validations_spec.rb +2 -0
- data/spec/grape/endpoint_spec.rb +21 -6
- data/spec/grape/entity_spec.rb +2 -0
- data/spec/grape/exceptions/base_spec.rb +3 -1
- data/spec/grape/exceptions/body_parse_errors_spec.rb +2 -0
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +2 -0
- data/spec/grape/exceptions/invalid_formatter_spec.rb +2 -0
- data/spec/grape/exceptions/invalid_response_spec.rb +2 -0
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +2 -0
- data/spec/grape/exceptions/missing_mime_type_spec.rb +2 -0
- data/spec/grape/exceptions/missing_option_spec.rb +2 -0
- data/spec/grape/exceptions/unknown_options_spec.rb +2 -0
- data/spec/grape/exceptions/unknown_validator_spec.rb +2 -0
- data/spec/grape/exceptions/validation_errors_spec.rb +4 -2
- data/spec/grape/exceptions/validation_spec.rb +3 -1
- data/spec/grape/extensions/param_builders/hash_spec.rb +2 -0
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +2 -0
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +2 -0
- data/spec/grape/integration/global_namespace_function_spec.rb +2 -0
- data/spec/grape/integration/rack_sendfile_spec.rb +14 -8
- data/spec/grape/integration/rack_spec.rb +3 -1
- data/spec/grape/loading_spec.rb +2 -0
- data/spec/grape/middleware/auth/base_spec.rb +2 -0
- data/spec/grape/middleware/auth/dsl_spec.rb +2 -0
- data/spec/grape/middleware/auth/strategies_spec.rb +3 -1
- data/spec/grape/middleware/base_spec.rb +2 -0
- data/spec/grape/middleware/error_spec.rb +2 -0
- data/spec/grape/middleware/exception_spec.rb +3 -1
- data/spec/grape/middleware/formatter_spec.rb +19 -12
- data/spec/grape/middleware/globals_spec.rb +2 -0
- data/spec/grape/middleware/stack_spec.rb +11 -0
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +3 -1
- data/spec/grape/middleware/versioner/header_spec.rb +3 -1
- data/spec/grape/middleware/versioner/param_spec.rb +3 -1
- data/spec/grape/middleware/versioner/path_spec.rb +3 -1
- data/spec/grape/middleware/versioner_spec.rb +2 -0
- data/spec/grape/named_api_spec.rb +2 -0
- data/spec/grape/parser_spec.rb +7 -5
- data/spec/grape/path_spec.rb +6 -4
- data/spec/grape/presenters/presenter_spec.rb +2 -0
- data/spec/grape/request_spec.rb +2 -0
- data/spec/grape/util/inheritable_setting_spec.rb +2 -0
- data/spec/grape/util/inheritable_values_spec.rb +2 -0
- data/spec/grape/util/reverse_stackable_values_spec.rb +2 -0
- data/spec/grape/util/stackable_values_spec.rb +3 -1
- data/spec/grape/util/strict_hash_configuration_spec.rb +2 -0
- data/spec/grape/validations/attributes_iterator_spec.rb +2 -0
- data/spec/grape/validations/instance_behaivour_spec.rb +5 -3
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +2 -0
- data/spec/grape/validations/params_scope_spec.rb +3 -1
- data/spec/grape/validations/single_attribute_iterator_spec.rb +18 -4
- data/spec/grape/validations/types/array_coercer_spec.rb +35 -0
- data/spec/grape/validations/types/primitive_coercer_spec.rb +135 -0
- data/spec/grape/validations/types/set_coercer_spec.rb +34 -0
- data/spec/grape/validations/types_spec.rb +9 -36
- data/spec/grape/validations/validators/all_or_none_spec.rb +2 -0
- data/spec/grape/validations/validators/allow_blank_spec.rb +2 -0
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +2 -0
- data/spec/grape/validations/validators/coerce_spec.rb +341 -136
- data/spec/grape/validations/validators/default_spec.rb +123 -0
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +14 -12
- data/spec/grape/validations/validators/except_values_spec.rb +3 -1
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +2 -0
- data/spec/grape/validations/validators/presence_spec.rb +30 -0
- data/spec/grape/validations/validators/regexp_spec.rb +2 -0
- data/spec/grape/validations/validators/same_as_spec.rb +2 -0
- data/spec/grape/validations/validators/values_spec.rb +30 -5
- data/spec/grape/validations_spec.rb +91 -33
- data/spec/integration/eager_load/eager_load_spec.rb +15 -0
- data/spec/integration/multi_json/json_spec.rb +2 -0
- data/spec/integration/multi_xml/xml_spec.rb +2 -0
- data/spec/shared/versioning_examples.rb +2 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/basic_auth_encode_helpers.rb +2 -0
- data/spec/support/content_type_helpers.rb +2 -0
- data/spec/support/eager_load.rb +19 -0
- data/spec/support/endpoint_faker.rb +2 -0
- data/spec/support/file_streamer.rb +2 -0
- data/spec/support/integer_helpers.rb +2 -0
- data/spec/support/versioned_helpers.rb +4 -2
- metadata +48 -28
- data/lib/grape/extensions/deep_hash_with_indifferent_access.rb +0 -18
- data/lib/grape/util/content_types.rb +0 -26
- data/lib/grape/validations/types/virtus_collection_patch.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 342f290903dcc993f0e60d0d15bee151f3425abf2b68a191da459d9ac47ac943
|
4
|
+
data.tar.gz: 5b03c2c50e3b485787fd9d7ae64130b7cfe56ca9a9128d51133e46e58562d151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6f78f911d63d73b8cd2422b8918d53fadfd963e4b212e555f9c8fac8d1dfe801ca2e29a9e1ca236e41a82c1b75a0e503062d5a87430c1821817fae83cfd8ffd
|
7
|
+
data.tar.gz: c856baf9f14a2eebb371f69bd35f6b7a555113e92eb9e35384901df09ac86dfcea691753ef9990123e54a335a0b9dca66b97170fb27a377cf0bb3f4f6e5233ae
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,100 @@
|
|
1
|
+
### 1.4.0 (2020/07/10)
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* [#1520](https://github.com/ruby-grape/grape/pull/1520): Un-deprecate stream-like objects - [@urkle](https://github.com/urkle).
|
6
|
+
* [#2060](https://github.com/ruby-grape/grape/pull/2060): Drop support for Ruby 2.4 - [@dblock](https://github.com/dblock).
|
7
|
+
* [#2060](https://github.com/ruby-grape/grape/pull/2060): Upgraded Rubocop to 0.84.0 - [@dblock](https://github.com/dblock).
|
8
|
+
* [#2077](https://github.com/ruby-grape/grape/pull/2077): Simplify logic for defining declared params - [@dnesteryuk](https://github.com/dnesteryuk).
|
9
|
+
* [#2084](https://github.com/ruby-grape/grape/pull/2084): Fix memory leak in path normalization - [@fcheung](https://github.com/fcheung).
|
10
|
+
|
11
|
+
#### Fixes
|
12
|
+
|
13
|
+
* [#2067](https://github.com/ruby-grape/grape/pull/2067): Coerce empty string to nil for all primitive types except String - [@petekinnecom](https://github.com/petekinnecom).
|
14
|
+
* [#2064](https://github.com/ruby-grape/grape/pull/2064): Fix Ruby 2.7 deprecation warning in `Grape::Middleware::Base#initialize` - [@skarger](https://github.com/skarger).
|
15
|
+
* [#2072](https://github.com/ruby-grape/grape/pull/2072): Fix `Grape.eager_load!` and `compile!` - [@stanhu](https://github.com/stanhu).
|
16
|
+
* [#2076](https://github.com/ruby-grape/grape/pull/2076): Make route information available for hooks when the automatically generated endpoints are invoked - [@anakinj](https://github.com/anakinj).
|
17
|
+
|
18
|
+
### 1.3.3 (2020/05/23)
|
19
|
+
|
20
|
+
#### Features
|
21
|
+
|
22
|
+
* [#2048](https://github.com/ruby-grape/grape/issues/2034): Grape Enterprise support is now available [via TideLift](https://tidelift.com/subscription/request-a-demo?utm_source=rubygems-grape&utm_medium=referral&utm_campaign=enterprise) - [@dblock](https://github.com/dblock).
|
23
|
+
* [#2039](https://github.com/ruby-grape/grape/pull/2039): Travis - update rails versions - [@ericproulx](https://github.com/ericproulx).
|
24
|
+
* [#2038](https://github.com/ruby-grape/grape/pull/2038): Travis - update ruby versions - [@ericproulx](https://github.com/ericproulx).
|
25
|
+
* [#2050](https://github.com/ruby-grape/grape/pull/2050): Refactor route public_send to AttributeTranslator - [@ericproulx](https://github.com/ericproulx).
|
26
|
+
|
27
|
+
#### Fixes
|
28
|
+
|
29
|
+
* [#2049](https://github.com/ruby-grape/grape/pull/2049): Coerce an empty string to nil in case of the bool type - [@dnesteryuk](https://github.com/dnesteryuk).
|
30
|
+
* [#2043](https://github.com/ruby-grape/grape/pull/2043): Modify declared for nested array and hash - [@kadotami](https://github.com/kadotami).
|
31
|
+
* [#2040](https://github.com/ruby-grape/grape/pull/2040): Fix a regression with Array of type nil - [@ericproulx](https://github.com/ericproulx).
|
32
|
+
* [#2054](https://github.com/ruby-grape/grape/pull/2054): Coercing of nested arrays - [@dnesteryuk](https://github.com/dnesteryuk).
|
33
|
+
* [#2050](https://github.com/ruby-grape/grape/pull/2053): Fix broken multiple mounts - [@Jack12816](https://github.com/Jack12816).
|
34
|
+
|
35
|
+
### 1.3.2 (2020/04/12)
|
36
|
+
|
37
|
+
#### Features
|
38
|
+
|
39
|
+
* [#2020](https://github.com/ruby-grape/grape/pull/2020): Reduce array allocation - [@ericproulx](https://github.com/ericproulx).
|
40
|
+
* [#2015](https://github.com/ruby-grape/grape/pull/2014): Reduce MatchData allocation - [@ericproulx](https://github.com/ericproulx).
|
41
|
+
* [#2014](https://github.com/ruby-grape/grape/pull/2014): Reduce total allocated arrays - [@ericproulx](https://github.com/ericproulx).
|
42
|
+
* [#2011](https://github.com/ruby-grape/grape/pull/2011): Reduce total retained regexes - [@ericproulx](https://github.com/ericproulx).
|
43
|
+
|
44
|
+
#### Fixes
|
45
|
+
|
46
|
+
* [#2033](https://github.com/ruby-grape/grape/pull/2033): Ensure `Float` params are correctly coerced to `BigDecimal` - [@tlconnor](https://github.com/tlconnor).
|
47
|
+
* [#2031](https://github.com/ruby-grape/grape/pull/2031): Fix a regression with an array of a custom type - [@dnesteryuk](https://github.com/dnesteryuk).
|
48
|
+
* [#2026](https://github.com/ruby-grape/grape/pull/2026): Fix a regression in `coerce_with` when coercion returns `nil` - [@misdoro](https://github.com/misdoro).
|
49
|
+
* [#2025](https://github.com/ruby-grape/grape/pull/2025): Fix Decimal type category - [@kdoya](https://github.com/kdoya).
|
50
|
+
* [#2019](https://github.com/ruby-grape/grape/pull/2019): Avoid coercing parameter with multiple types to an empty Array - [@stanhu](https://github.com/stanhu).
|
51
|
+
|
52
|
+
### 1.3.1 (2020/03/11)
|
53
|
+
|
54
|
+
#### Features
|
55
|
+
|
56
|
+
* [#2005](https://github.com/ruby-grape/grape/pull/2005): Content types registrable - [@ericproulx](https://github.com/ericproulx).
|
57
|
+
* [#2003](https://github.com/ruby-grape/grape/pull/2003): Upgraded Rubocop to 0.80.1 - [@ericproulx](https://github.com/ericproulx).
|
58
|
+
* [#2002](https://github.com/ruby-grape/grape/pull/2002): Objects allocation optimization (lazy_lookup) - [@ericproulx](https://github.com/ericproulx).
|
59
|
+
|
60
|
+
#### Fixes
|
61
|
+
|
62
|
+
* [#2006](https://github.com/ruby-grape/grape/pull/2006): Fix explicit rescue StandardError - [@ericproulx](https://github.com/ericproulx).
|
63
|
+
* [#2004](https://github.com/ruby-grape/grape/pull/2004): Rubocop fixes - [@ericproulx](https://github.com/ericproulx).
|
64
|
+
* [#1995](https://github.com/ruby-grape/grape/pull/1995): Fix: "undefined instance variables" and "method redefined" warnings - [@nbeyer](https://github.com/nbeyer).
|
65
|
+
* [#1994](https://github.com/ruby-grape/grape/pull/1993): Fix typos in README - [@bellmyer](https://github.com/bellmyer).
|
66
|
+
* [#1993](https://github.com/ruby-grape/grape/pull/1993): Lazy join allow header - [@ericproulx](https://github.com/ericproulx).
|
67
|
+
* [#1987](https://github.com/ruby-grape/grape/pull/1987): Re-add exactly_one_of mutually exclusive error message - [@ZeroInputCtrl](https://github.com/ZeroInputCtrl).
|
68
|
+
* [#1977](https://github.com/ruby-grape/grape/pull/1977): Skip validation for a file if it is optional and nil - [@dnesteryuk](https://github.com/dnesteryuk).
|
69
|
+
* [#1976](https://github.com/ruby-grape/grape/pull/1976): Ensure classes/modules listed for autoload really exist - [@dnesteryuk](https://github.com/dnesteryuk).
|
70
|
+
* [#1971](https://github.com/ruby-grape/grape/pull/1971): Fix BigDecimal coercion - [@FlickStuart](https://github.com/FlickStuart).
|
71
|
+
* [#1968](https://github.com/ruby-grape/grape/pull/1968): Fix args forwarding in Grape::Middleware::Stack#merge_with for ruby 2.7.0 - [@dm1try](https://github.com/dm1try).
|
72
|
+
* [#1988](https://github.com/ruby-grape/grape/pull/1988): Refactor the full_messages method and stop overriding full_message - [@hosseintoussi](https://github.com/hosseintoussi).
|
73
|
+
* [#1956](https://github.com/ruby-grape/grape/pull/1956): Comply with Rack spec, fix `undefined method [] for nil:NilClass` error when upgrading Rack - [@ioquatix](https://github.com/ioquatix).
|
74
|
+
|
75
|
+
### 1.3.0 (2020/01/11)
|
76
|
+
|
77
|
+
#### Features
|
78
|
+
|
79
|
+
* [#1949](https://github.com/ruby-grape/grape/pull/1949): Add support for Ruby 2.7 - [@nbulaj](https://github.com/nbulaj).
|
80
|
+
* [#1948](https://github.com/ruby-grape/grape/pull/1948): Relax `dry-types` dependency version - [@nbulaj](https://github.com/nbulaj).
|
81
|
+
* [#1944](https://github.com/ruby-grape/grape/pull/1944): Reduces `attribute_translator` string allocations - [@ericproulx](https://github.com/ericproulx).
|
82
|
+
* [#1943](https://github.com/ruby-grape/grape/pull/1943): Reduces number of regex string allocations - [@ericproulx](https://github.com/ericproulx).
|
83
|
+
* [#1942](https://github.com/ruby-grape/grape/pull/1942): Optimizes retained memory methods - [@ericproulx](https://github.com/ericproulx).
|
84
|
+
* [#1941](https://github.com/ruby-grape/grape/pull/1941): Adds frozen string literal - [@ericproulx](https://github.com/ericproulx).
|
85
|
+
* [#1940](https://github.com/ruby-grape/grape/pull/1940): Gets rid of a needless step in `HashWithIndifferentAccess` - [@dnesteryuk](https://github.com/dnesteryuk).
|
86
|
+
* [#1938](https://github.com/ruby-grape/grape/pull/1938): Adds project metadata to the gemspec - [@orien](https://github.com/orien).
|
87
|
+
* [#1920](https://github.com/ruby-grape/grape/pull/1920): Replaces Virtus with dry-types - [@dnesteryuk](https://github.com/dnesteryuk).
|
88
|
+
* [#1930](https://github.com/ruby-grape/grape/pull/1930): Moves block call to separate method so it can be spied on - [@estolfo](https://github.com/estolfo).
|
89
|
+
|
90
|
+
#### Fixes
|
91
|
+
|
92
|
+
* [#1965](https://github.com/ruby-grape/grape/pull/1965): Fix typos in README - [@davidalee](https://github.com/davidalee).
|
93
|
+
* [#1963](https://github.com/ruby-grape/grape/pull/1963): The values validator must properly work with booleans - [@dnesteryuk](https://github.com/dnesteryuk).
|
94
|
+
* [#1950](https://github.com/ruby-grape/grape/pull/1950): Consider the allow_blank option in the values validator - [@dnesteryuk](https://github.com/dnesteryuk).
|
95
|
+
* [#1947](https://github.com/ruby-grape/grape/pull/1947): Careful check for empty params - [@dnesteryuk](https://github.com/dnesteryuk).
|
96
|
+
* [#1931](https://github.com/ruby-grape/grape/pull/1946): Fixes issue when using namespaces in `Grape::API::Instance` mounted directly - [@myxoh](https://github.com/myxoh).
|
97
|
+
|
1
98
|
### 1.2.5 (2019/12/01)
|
2
99
|
|
3
100
|
#### Features
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010-
|
1
|
+
Copyright (c) 2010-2020 Michael Bleigh, Intridea Inc. and Contributors.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
- [What is Grape?](#what-is-grape)
|
13
13
|
- [Stable Release](#stable-release)
|
14
14
|
- [Project Resources](#project-resources)
|
15
|
+
- [Grape for Enterprise](#grape-for-enterprise)
|
15
16
|
- [Installation](#installation)
|
16
17
|
- [Basic Usage](#basic-usage)
|
17
18
|
- [Mounting](#mounting)
|
@@ -141,6 +142,7 @@
|
|
141
142
|
- [format_response.grape](#format_responsegrape)
|
142
143
|
- [Monitoring Products](#monitoring-products)
|
143
144
|
- [Contributing to Grape](#contributing-to-grape)
|
145
|
+
- [Security](#security)
|
144
146
|
- [License](#license)
|
145
147
|
- [Copyright](#copyright)
|
146
148
|
|
@@ -154,7 +156,7 @@ content negotiation, versioning and much more.
|
|
154
156
|
|
155
157
|
## Stable Release
|
156
158
|
|
157
|
-
You're reading the documentation for the stable release of Grape,
|
159
|
+
You're reading the documentation for the stable release of Grape, 1.4.0.
|
158
160
|
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
159
161
|
|
160
162
|
## Project Resources
|
@@ -164,8 +166,18 @@ Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
|
164
166
|
* Need help? Try [Grape Google Group](http://groups.google.com/group/ruby-grape) or [Gitter](https://gitter.im/ruby-grape/grape)
|
165
167
|
* [Follow us on Twitter](https://twitter.com/grapeframework)
|
166
168
|
|
169
|
+
## Grape for Enterprise
|
170
|
+
|
171
|
+
Available as part of the Tidelift Subscription.
|
172
|
+
|
173
|
+
The maintainers of Grape are working with Tidelift to deliver commercial support and maintenance. Save time, reduce risk, and improve code health, while paying the maintainers of Grape. Click [here](https://tidelift.com/subscription/request-a-demo?utm_source=rubygems-grape&utm_medium=referral&utm_campaign=enterprise) for more details.
|
174
|
+
|
175
|
+
In 2020, we plan to use the money towards gathering Grape contributors for dinner in New York City.
|
176
|
+
|
167
177
|
## Installation
|
168
178
|
|
179
|
+
Ruby 2.4 or newer is required.
|
180
|
+
|
169
181
|
Grape is available as a gem, to install it just install the gem:
|
170
182
|
|
171
183
|
gem install grape
|
@@ -1046,13 +1058,13 @@ params do
|
|
1046
1058
|
end
|
1047
1059
|
```
|
1048
1060
|
|
1049
|
-
Note that default values will be passed through to any validation options specified.
|
1050
|
-
The following example will always fail if `:color` is not explicitly provided.
|
1051
|
-
|
1052
1061
|
Default values are eagerly evaluated. Above `:non_random_number` will evaluate to the same
|
1053
1062
|
number for each call to the endpoint of this `params` block. To have the default evaluate
|
1054
1063
|
lazily with each request use a lambda, like `:random_number` above.
|
1055
1064
|
|
1065
|
+
Note that default values will be passed through to any validation options specified.
|
1066
|
+
The following example will always fail if `:color` is not explicitly provided.
|
1067
|
+
|
1056
1068
|
```ruby
|
1057
1069
|
params do
|
1058
1070
|
optional :color, type: String, default: 'blue', values: ['red', 'green']
|
@@ -1720,7 +1732,7 @@ params do
|
|
1720
1732
|
end
|
1721
1733
|
```
|
1722
1734
|
|
1723
|
-
Every validation will have
|
1735
|
+
Every validation will have its own instance of the validator, which means that the validator can have a state.
|
1724
1736
|
|
1725
1737
|
### Validation Errors
|
1726
1738
|
|
@@ -3155,17 +3167,19 @@ end
|
|
3155
3167
|
|
3156
3168
|
Use `body false` to return `204 No Content` without any data or content-type.
|
3157
3169
|
|
3158
|
-
You can also set the response to a file with `
|
3170
|
+
You can also set the response to a file with `sendfile`. This works with the
|
3171
|
+
[Rack::Sendfile](https://www.rubydoc.info/gems/rack/Rack/Sendfile) middleware to optimally send
|
3172
|
+
the file through your web server software.
|
3159
3173
|
|
3160
3174
|
```ruby
|
3161
3175
|
class API < Grape::API
|
3162
3176
|
get '/' do
|
3163
|
-
|
3177
|
+
sendfile '/path/to/file'
|
3164
3178
|
end
|
3165
3179
|
end
|
3166
3180
|
```
|
3167
3181
|
|
3168
|
-
|
3182
|
+
To stream a file in chunks use `stream`
|
3169
3183
|
|
3170
3184
|
```ruby
|
3171
3185
|
class API < Grape::API
|
@@ -3175,6 +3189,26 @@ class API < Grape::API
|
|
3175
3189
|
end
|
3176
3190
|
```
|
3177
3191
|
|
3192
|
+
If you want to stream non-file data use the `stream` method and a `Stream` object.
|
3193
|
+
This is an object that responds to `each` and yields for each chunk to send to the client.
|
3194
|
+
Each chunk will be sent as it is yielded instead of waiting for all of the content to be available.
|
3195
|
+
|
3196
|
+
```ruby
|
3197
|
+
class MyStream
|
3198
|
+
def each
|
3199
|
+
yield 'part 1'
|
3200
|
+
yield 'part 2'
|
3201
|
+
yield 'part 3'
|
3202
|
+
end
|
3203
|
+
end
|
3204
|
+
|
3205
|
+
class API < Grape::API
|
3206
|
+
get '/' do
|
3207
|
+
stream MyStream.new
|
3208
|
+
end
|
3209
|
+
end
|
3210
|
+
```
|
3211
|
+
|
3178
3212
|
## Authentication
|
3179
3213
|
|
3180
3214
|
### Basic and Digest Auth
|
@@ -3186,14 +3220,13 @@ applies to the current namespace and any children, but not parents.
|
|
3186
3220
|
```ruby
|
3187
3221
|
http_basic do |username, password|
|
3188
3222
|
# verify user's password here
|
3189
|
-
|
3223
|
+
# IMPORTANT: make sure you use a comparison method which isn't prone to a timing attack
|
3190
3224
|
end
|
3191
3225
|
```
|
3192
3226
|
|
3193
3227
|
```ruby
|
3194
3228
|
http_digest({ realm: 'Test Api', opaque: 'app secret' }) do |username|
|
3195
3229
|
# lookup the user's password here
|
3196
|
-
{ 'user1' => 'password1' }[username]
|
3197
3230
|
end
|
3198
3231
|
```
|
3199
3232
|
|
@@ -3226,7 +3259,7 @@ end
|
|
3226
3259
|
|
3227
3260
|
Use [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper), [warden-oauth2](https://github.com/opperator/warden-oauth2) or [rack-oauth2](https://github.com/nov/rack-oauth2) for OAuth2 support.
|
3228
3261
|
|
3229
|
-
You can access the controller params, headers, and helpers through the context with the `#context` method inside any auth middleware inherited from `Grape::
|
3262
|
+
You can access the controller params, headers, and helpers through the context with the `#context` method inside any auth middleware inherited from `Grape::Middleware::Auth::Base`.
|
3230
3263
|
|
3231
3264
|
## Describing and Inspecting an API
|
3232
3265
|
|
@@ -3299,7 +3332,7 @@ end
|
|
3299
3332
|
|
3300
3333
|
Blocks can be executed before or after every API call, using `before`, `after`,
|
3301
3334
|
`before_validation` and `after_validation`.
|
3302
|
-
If the API fails the `after` call will not be
|
3335
|
+
If the API fails the `after` call will not be triggered, if you need code to execute for sure
|
3303
3336
|
use the `finally`.
|
3304
3337
|
|
3305
3338
|
Before and after callbacks execute in the following order:
|
@@ -3540,7 +3573,7 @@ class API < Grape::API
|
|
3540
3573
|
end
|
3541
3574
|
```
|
3542
3575
|
|
3543
|
-
You can access the controller params, headers, and helpers through the context with the `#context` method inside any middleware inherited from `Grape::
|
3576
|
+
You can access the controller params, headers, and helpers through the context with the `#context` method inside any middleware inherited from `Grape::Middleware::Base`.
|
3544
3577
|
|
3545
3578
|
### Rails Middleware
|
3546
3579
|
|
@@ -3850,7 +3883,7 @@ Grape integrates with following third-party tools:
|
|
3850
3883
|
* **Librato Metrics** - [grape-librato](https://github.com/seanmoon/grape-librato) gem
|
3851
3884
|
* **[Skylight](https://www.skylight.io/)** - [skylight](https://github.com/skylightio/skylight-ruby) gem, [documentation](https://docs.skylight.io/grape/)
|
3852
3885
|
* **[AppSignal](https://www.appsignal.com)** - [appsignal-ruby](https://github.com/appsignal/appsignal-ruby) gem, [documentation](http://docs.appsignal.com/getting-started/supported-frameworks.html#grape)
|
3853
|
-
* **[ElasticAPM](https://www.elastic.co/products/apm) - [elastic-apm](https://github.com/elastic/apm-agent-ruby) gem, [documentation](https://www.elastic.co/guide/en/apm/agent/ruby/3.x/getting-started-rack.html#getting-started-grape)
|
3886
|
+
* **[ElasticAPM](https://www.elastic.co/products/apm)** - [elastic-apm](https://github.com/elastic/apm-agent-ruby) gem, [documentation](https://www.elastic.co/guide/en/apm/agent/ruby/3.x/getting-started-rack.html#getting-started-grape)
|
3854
3887
|
|
3855
3888
|
## Contributing to Grape
|
3856
3889
|
|
@@ -3859,10 +3892,14 @@ features and discuss issues.
|
|
3859
3892
|
|
3860
3893
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
3861
3894
|
|
3895
|
+
## Security
|
3896
|
+
|
3897
|
+
See [SECURITY](SECURITY.md) for details.
|
3898
|
+
|
3862
3899
|
## License
|
3863
3900
|
|
3864
|
-
MIT License. See LICENSE for details.
|
3901
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
3865
3902
|
|
3866
3903
|
## Copyright
|
3867
3904
|
|
3868
|
-
Copyright (c) 2010-
|
3905
|
+
Copyright (c) 2010-2020 Michael Bleigh, Intridea Inc. and Contributors.
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,223 @@
|
|
1
1
|
Upgrading Grape
|
2
2
|
===============
|
3
3
|
|
4
|
+
### Upgrading to >= 1.4.0
|
5
|
+
|
6
|
+
#### Reworking stream and file and un-deprecating stream like-objects
|
7
|
+
|
8
|
+
Previously in 0.16 stream-like objects were deprecated. This release restores their functionality for use-cases other than file streaming.
|
9
|
+
|
10
|
+
This release deprecated `file` in favor of `sendfile` to better document its purpose.
|
11
|
+
|
12
|
+
To deliver a file via the Sendfile support in your web server and have the Rack::Sendfile middleware enabled. See [`Rack::Sendfile`](https://www.rubydoc.info/gems/rack/Rack/Sendfile).
|
13
|
+
```ruby
|
14
|
+
class API < Grape::API
|
15
|
+
get '/' do
|
16
|
+
sendfile '/path/to/file'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
Use `stream` to stream file content in chunks.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class API < Grape::API
|
25
|
+
get '/' do
|
26
|
+
stream '/path/to/file'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Or use `stream` to stream other kinds of content. In the following example a streamer class
|
32
|
+
streams paginated data from a database.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class MyObject
|
36
|
+
attr_accessor :result
|
37
|
+
|
38
|
+
def initialize(query)
|
39
|
+
@result = query
|
40
|
+
end
|
41
|
+
|
42
|
+
def each
|
43
|
+
yield '['
|
44
|
+
# Do paginated DB fetches and return each page formatted
|
45
|
+
first = false
|
46
|
+
result.find_in_batches do |records|
|
47
|
+
yield process_records(records, first)
|
48
|
+
first = false
|
49
|
+
end
|
50
|
+
yield ']'
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_records(records, first)
|
54
|
+
buffer = +''
|
55
|
+
buffer << ',' unless first
|
56
|
+
buffer << records.map(&:to_json).join(',')
|
57
|
+
buffer
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class API < Grape::API
|
62
|
+
get '/' do
|
63
|
+
stream MyObject.new(Sprocket.all)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### Upgrading to >= 1.3.3
|
69
|
+
|
70
|
+
#### Nil values for structures
|
71
|
+
|
72
|
+
Nil values always been a special case when dealing with types especially with the following structures:
|
73
|
+
|
74
|
+
- Array
|
75
|
+
- Hash
|
76
|
+
- Set
|
77
|
+
|
78
|
+
The behavior for these structures has change through out the latest releases. For example:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class Api < Grape::API
|
82
|
+
params do
|
83
|
+
require :my_param, type: Array[Integer]
|
84
|
+
end
|
85
|
+
|
86
|
+
get 'example' do
|
87
|
+
params[:my_param]
|
88
|
+
end
|
89
|
+
get '/example', params: { my_param: nil }
|
90
|
+
# 1.3.1 = []
|
91
|
+
# 1.3.2 = nil
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
For now on, `nil` values stay `nil` values for all types, including arrays, sets and hashes.
|
96
|
+
|
97
|
+
If you want to have the same behavior as 1.3.1, apply a `default` validator:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
class Api < Grape::API
|
101
|
+
params do
|
102
|
+
require :my_param, type: Array[Integer], default: []
|
103
|
+
end
|
104
|
+
|
105
|
+
get 'example' do
|
106
|
+
params[:my_param]
|
107
|
+
end
|
108
|
+
get '/example', params: { my_param: nil } # => []
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
#### Default validator
|
113
|
+
|
114
|
+
Default validator is now applied for `nil` values.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
class Api < Grape::API
|
118
|
+
params do
|
119
|
+
requires :my_param, type: Integer, default: 0
|
120
|
+
end
|
121
|
+
|
122
|
+
get 'example' do
|
123
|
+
params[:my_param]
|
124
|
+
end
|
125
|
+
get '/example', params: { my_param: nil } #=> before: nil, after: 0
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
### Upgrading to >= 1.3.0
|
130
|
+
|
131
|
+
#### Ruby
|
132
|
+
|
133
|
+
After adding dry-types, Ruby 2.4 or newer is required.
|
134
|
+
|
135
|
+
#### Coercion
|
136
|
+
|
137
|
+
[Virtus](https://github.com/solnic/virtus) has been replaced by [dry-types](https://dry-rb.org/gems/dry-types/1.2/) for parameter coercion. If your project depends on Virtus outside of Grape, explicitly add it to your `Gemfile`.
|
138
|
+
|
139
|
+
Here's an example of how to migrate a custom type from Virtus to dry-types:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# Legacy Grape parser
|
143
|
+
class SecureUriType < Virtus::Attribute
|
144
|
+
def coerce(input)
|
145
|
+
URI.parse value
|
146
|
+
end
|
147
|
+
|
148
|
+
def value_coerced?(input)
|
149
|
+
value.is_a? String
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
params do
|
154
|
+
requires :secure_uri, type: SecureUri
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
To use dry-types, we need to:
|
159
|
+
|
160
|
+
1. Remove the inheritance of `Virtus::Attribute`
|
161
|
+
1. Rename `coerce` to `self.parse`
|
162
|
+
1. Rename `value_coerced?` to `self.parsed?`
|
163
|
+
|
164
|
+
The custom type must have a class-level `parse` method to the model. A class-level `parsed?` is needed if the parsed type differs from the defined type. In the example below, since `SecureUri` is not the same as `URI::HTTPS`, `self.parsed?` is needed:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
# New dry-types parser
|
168
|
+
class SecureUri
|
169
|
+
def self.parse(value)
|
170
|
+
URI.parse value
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.parsed?(value)
|
174
|
+
value.is_a? URI::HTTPS
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
params do
|
179
|
+
requires :secure_uri, type: SecureUri
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
#### Coercing to `FalseClass` or `TrueClass` no longer works
|
184
|
+
|
185
|
+
Previous Grape versions allowed this, though it wasn't documented:
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
requires :true_value, type: TrueClass
|
189
|
+
requires :bool_value, types: [FalseClass, TrueClass]
|
190
|
+
```
|
191
|
+
|
192
|
+
This is no longer supported, if you do this, your values will never be valid. Instead you should do this:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
requires :true_value, type: Boolean # in your endpoint you should validate if this is actually `true`
|
196
|
+
requires :bool_value, type: Boolean
|
197
|
+
```
|
198
|
+
|
199
|
+
#### Ensure that Array types have explicit coercions
|
200
|
+
|
201
|
+
Unlike Virtus, dry-types does not perform any implict coercions. If you have any uses of `Array[String]`, `Array[Integer]`, etc. be sure they use a `coerce_with` block. For example:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
requires :values, type: Array[String]
|
205
|
+
```
|
206
|
+
|
207
|
+
It's quite common to pass a comma-separated list, such as `tag1,tag2` as `values`. Previously Virtus would implicitly coerce this to `Array(values)` so that `["tag1,tag2"]` would pass the type checks, but with `dry-types` the values are no longer coerced for you. To fix this, you might do:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
requires :values, type: Array[String], coerce_with: ->(val) { val.split(',').map(&:strip) }
|
211
|
+
```
|
212
|
+
|
213
|
+
Likewise, for `Array[Integer]`, you might do:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
requires :values, type: Array[Integer], coerce_with: ->(val) { val.split(',').map(&:strip).map(&:to_i) }
|
217
|
+
```
|
218
|
+
|
219
|
+
For more information see [#1920](https://github.com/ruby-grape/grape/pull/1920).
|
220
|
+
|
4
221
|
### Upgrading to >= 1.2.4
|
5
222
|
|
6
223
|
#### Headers in `error!` call
|
@@ -54,12 +271,9 @@ In order to make obtaining the name of a mounted class simpler, we've delegated
|
|
54
271
|
|
55
272
|
##### Patching the class
|
56
273
|
|
57
|
-
In an effort to make APIs re-mountable, The class `Grape::API` no longer refers to an API instance,
|
58
|
-
rather, what used to be `Grape::API` is now `Grape::API::Instance` and `Grape::API` was replaced
|
59
|
-
with a class that can contain several instances of `Grape::API`.
|
274
|
+
In an effort to make APIs re-mountable, The class `Grape::API` no longer refers to an API instance, rather, what used to be `Grape::API` is now `Grape::API::Instance` and `Grape::API` was replaced with a class that can contain several instances of `Grape::API`.
|
60
275
|
|
61
|
-
This changes were done in such a way that no code-changes should be required.
|
62
|
-
However, if experiencing problems, or relying on private methods and internal behaviour too deeply, it is possible to restore the prior behaviour by replacing the references from `Grape::API` to `Grape::API::Instance`.
|
276
|
+
This changes were done in such a way that no code-changes should be required. However, if experiencing problems, or relying on private methods and internal behaviour too deeply, it is possible to restore the prior behaviour by replacing the references from `Grape::API` to `Grape::API::Instance`.
|
63
277
|
|
64
278
|
Note, this is particularly relevant if you are opening the class `Grape::API` for modification.
|
65
279
|
|
@@ -82,15 +296,20 @@ end
|
|
82
296
|
|
83
297
|
After the patch, the mounted API is no longer a Named class inheriting from `Grape::API`, it is an anonymous class
|
84
298
|
which inherit from `Grape::API::Instance`.
|
299
|
+
|
85
300
|
What this means in practice, is:
|
301
|
+
|
86
302
|
- Generally: you can access the named class from the instance calling the getter `base`.
|
87
|
-
- In particular: If you need the `name`, you can use `base`.`name
|
303
|
+
- In particular: If you need the `name`, you can use `base`.`name`.
|
88
304
|
|
89
305
|
**Deprecated**
|
306
|
+
|
90
307
|
```ruby
|
91
308
|
payload[:endpoint].options[:for].name
|
92
309
|
```
|
310
|
+
|
93
311
|
**New**
|
312
|
+
|
94
313
|
```ruby
|
95
314
|
payload[:endpoint].options[:for].base.name
|
96
315
|
```
|
@@ -181,8 +400,7 @@ See [#1610](https://github.com/ruby-grape/grape/pull/1610) for more information.
|
|
181
400
|
|
182
401
|
#### The `except`, `except_message`, and `proc` options of the `values` validator are deprecated.
|
183
402
|
|
184
|
-
The new `except_values` validator should be used in place of the `except` and `except_message` options of
|
185
|
-
the `values` validator.
|
403
|
+
The new `except_values` validator should be used in place of the `except` and `except_message` options of the `values` validator.
|
186
404
|
|
187
405
|
Arity one Procs may now be used directly as the `values` option to explicitly test param values.
|
188
406
|
|
@@ -258,9 +476,7 @@ get '/example' #=> before: 405, after: 404
|
|
258
476
|
|
259
477
|
#### Removed param processing from built-in OPTIONS handler
|
260
478
|
|
261
|
-
When a request is made to the built-in `OPTIONS` handler, only the `before` and `after`
|
262
|
-
callbacks associated with the resource will be run. The `before_validation` and
|
263
|
-
`after_validation` callbacks and parameter validations will be skipped.
|
479
|
+
When a request is made to the built-in `OPTIONS` handler, only the `before` and `after` callbacks associated with the resource will be run. The `before_validation` and `after_validation` callbacks and parameter validations will be skipped.
|
264
480
|
|
265
481
|
See [#1505](https://github.com/ruby-grape/grape/pull/1505) for more information.
|
266
482
|
|
@@ -281,8 +497,7 @@ See [#1510](https://github.com/ruby-grape/grape/pull/1510) for more information.
|
|
281
497
|
|
282
498
|
#### The default status code for DELETE is now 204 instead of 200.
|
283
499
|
|
284
|
-
Breaking change: Sets the default response status code for a delete request to 204.
|
285
|
-
A status of 204 makes the response more distinguishable and therefore easier to handle on the client side, particularly because a DELETE request typically returns an empty body as the resource was deleted or voided.
|
500
|
+
Breaking change: Sets the default response status code for a delete request to 204. A status of 204 makes the response more distinguishable and therefore easier to handle on the client side, particularly because a DELETE request typically returns an empty body as the resource was deleted or voided.
|
286
501
|
|
287
502
|
To achieve the old behavior, one has to set it explicitly:
|
288
503
|
```ruby
|
@@ -460,18 +675,14 @@ See [#1114](https://github.com/ruby-grape/grape/pull/1114) for more information.
|
|
460
675
|
|
461
676
|
#### Bypasses formatters when status code indicates no content
|
462
677
|
|
463
|
-
To be consistent with rack and it's handling of standard responses
|
464
|
-
associated with no content, both default and custom formatters will now
|
678
|
+
To be consistent with rack and it's handling of standard responses associated with no content, both default and custom formatters will now
|
465
679
|
be bypassed when processing responses for status codes defined [by rack](https://github.com/rack/rack/blob/master/lib/rack/utils.rb#L567)
|
466
680
|
|
467
681
|
See [#1190](https://github.com/ruby-grape/grape/pull/1190) for more information.
|
468
682
|
|
469
683
|
#### Redirects respond as plain text with message
|
470
684
|
|
471
|
-
`#redirect` now uses `text/plain` regardless of whether that format has
|
472
|
-
been enabled. This prevents formatters from attempting to serialize the
|
473
|
-
message body and allows for a descriptive message body to be provided - and
|
474
|
-
optionally overridden - that better fulfills the theme of the HTTP spec.
|
685
|
+
`#redirect` now uses `text/plain` regardless of whether that format has been enabled. This prevents formatters from attempting to serialize the message body and allows for a descriptive message body to be provided - and optionally overridden - that better fulfills the theme of the HTTP spec.
|
475
686
|
|
476
687
|
See [#1194](https://github.com/ruby-grape/grape/pull/1194) for more information.
|
477
688
|
|
@@ -505,10 +716,7 @@ end
|
|
505
716
|
|
506
717
|
See [#1029](https://github.com/ruby-grape/grape/pull/1029) for more information.
|
507
718
|
|
508
|
-
There is a known issue because of this change. When Grape is used with an older
|
509
|
-
than 1.2.4 version of [warden](https://github.com/hassox/warden) there may be raised
|
510
|
-
the following exception having the [rack-mount](https://github.com/jm/rack-mount) gem's
|
511
|
-
lines as last ones in the backtrace:
|
719
|
+
There is a known issue because of this change. When Grape is used with an older than 1.2.4 version of [warden](https://github.com/hassox/warden) there may be raised the following exception having the [rack-mount](https://github.com/jm/rack-mount) gem's lines as last ones in the backtrace:
|
512
720
|
|
513
721
|
```
|
514
722
|
NoMethodError: undefined method `[]' for nil:NilClass
|