grape 1.3.3 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -2
- data/CONTRIBUTING.md +2 -1
- data/README.md +135 -23
- data/UPGRADING.md +237 -46
- data/grape.gemspec +5 -5
- data/lib/grape/api/instance.rb +34 -42
- data/lib/grape/api.rb +21 -16
- data/lib/grape/cookies.rb +2 -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 +8 -5
- data/lib/grape/dsl/inside_route.rb +72 -53
- data/lib/grape/dsl/middleware.rb +4 -4
- data/lib/grape/dsl/parameters.rb +11 -7
- data/lib/grape/dsl/request_response.rb +9 -6
- data/lib/grape/dsl/routing.rb +8 -9
- data/lib/grape/dsl/settings.rb +5 -5
- data/lib/grape/dsl/validations.rb +18 -1
- data/lib/grape/eager_load.rb +1 -1
- data/lib/grape/endpoint.rb +29 -42
- 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 +6 -3
- data/lib/grape/middleware/error.rb +11 -13
- data/lib/grape/middleware/formatter.rb +7 -7
- data/lib/grape/middleware/stack.rb +10 -3
- data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
- data/lib/grape/middleware/versioner/header.rb +6 -4
- data/lib/grape/middleware/versioner/param.rb +1 -0
- data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
- data/lib/grape/middleware/versioner/path.rb +2 -0
- data/lib/grape/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 +4 -1
- data/lib/grape/router/attribute_translator.rb +3 -3
- data/lib/grape/router/pattern.rb +1 -1
- data/lib/grape/router/route.rb +2 -2
- data/lib/grape/router.rb +31 -30
- data/lib/grape/{serve_file → serve_stream}/file_body.rb +1 -1
- data/lib/grape/{serve_file → serve_stream}/sendfile_response.rb +1 -1
- data/lib/grape/{serve_file/file_response.rb → serve_stream/stream_response.rb} +8 -8
- data/lib/grape/util/base_inheritable.rb +2 -2
- data/lib/grape/util/inheritable_setting.rb +1 -3
- data/lib/grape/util/lazy_value.rb +4 -2
- data/lib/grape/util/strict_hash_configuration.rb +1 -1
- data/lib/grape/validations/attributes_iterator.rb +8 -0
- data/lib/grape/validations/multiple_attributes_iterator.rb +1 -1
- data/lib/grape/validations/params_scope.rb +97 -62
- data/lib/grape/validations/single_attribute_iterator.rb +1 -1
- data/lib/grape/validations/types/custom_type_coercer.rb +16 -3
- data/lib/grape/validations/types/dry_type_coercer.rb +1 -1
- data/lib/grape/validations/types/invalid_value.rb +24 -0
- data/lib/grape/validations/types/json.rb +2 -1
- data/lib/grape/validations/types/primitive_coercer.rb +4 -5
- data/lib/grape/validations/types.rb +1 -4
- data/lib/grape/validations/validator_factory.rb +1 -1
- data/lib/grape/validations/validators/all_or_none.rb +8 -5
- data/lib/grape/validations/validators/allow_blank.rb +9 -7
- data/lib/grape/validations/validators/as.rb +6 -8
- data/lib/grape/validations/validators/at_least_one_of.rb +7 -4
- data/lib/grape/validations/validators/base.rb +74 -69
- data/lib/grape/validations/validators/coerce.rb +63 -76
- data/lib/grape/validations/validators/default.rb +36 -34
- data/lib/grape/validations/validators/exactly_one_of.rb +9 -6
- data/lib/grape/validations/validators/except_values.rb +13 -11
- data/lib/grape/validations/validators/multiple_params_base.rb +24 -19
- data/lib/grape/validations/validators/mutual_exclusion.rb +8 -5
- data/lib/grape/validations/validators/presence.rb +7 -4
- data/lib/grape/validations/validators/regexp.rb +8 -5
- data/lib/grape/validations/validators/same_as.rb +18 -15
- data/lib/grape/validations/validators/values.rb +61 -56
- data/lib/grape/validations.rb +6 -0
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +7 -3
- 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 +576 -211
- 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 +185 -34
- 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 +848 -0
- data/spec/grape/endpoint_spec.rb +77 -589
- data/spec/grape/entity_spec.rb +29 -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 +13 -9
- 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 +61 -21
- data/spec/grape/middleware/base_spec.rb +24 -15
- data/spec/grape/middleware/error_spec.rb +3 -3
- data/spec/grape/middleware/exception_spec.rb +111 -161
- data/spec/grape/middleware/formatter_spec.rb +28 -7
- data/spec/grape/middleware/globals_spec.rb +7 -4
- data/spec/grape/middleware/stack_spec.rb +15 -12
- 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 +14 -3
- data/spec/grape/validations/params_scope_spec.rb +72 -10
- data/spec/grape/validations/single_attribute_iterator_spec.rb +18 -6
- data/spec/grape/validations/types/primitive_coercer_spec.rb +63 -7
- 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 +248 -33
- data/spec/grape/validations/validators/default_spec.rb +121 -78
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
- data/spec/grape/validations/validators/except_values_spec.rb +4 -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 +342 -29
- data/spec/integration/eager_load/eager_load_spec.rb +15 -0
- 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 -12
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- data/spec/support/chunks.rb +14 -0
- data/spec/support/versioned_helpers.rb +4 -6
- metadata +110 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d182a6dfa2a571345d24a6a2b7286b4a2b34eeedc6570334ba2259fdda59faac
|
4
|
+
data.tar.gz: c365091e871e7ad78dd46dc0aab52cdd41d1e5ddb5a46503fcf0020af45f4324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 539fdf761a5058dfcb3bab993a7fac3c7223ec06e0b828e102cb52095ac79f63668ebab1c1c4b47bf16984990c94f9a291537e7b2a1359626736b7abdd2c34ec
|
7
|
+
data.tar.gz: 2b30d941ab114aab53c4f4630742adedd037856ecc63b65f87b0df506349a13eed092964d9f53c003774006e74b9800043178b2ad2e6c55b0d5d42f6039a7e71
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,111 @@
|
|
1
|
+
### 1.6.2 (2021/12/30)
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
#### Fixes
|
6
|
+
|
7
|
+
* [#2219](https://github.com/ruby-grape/grape/pull/2219): Revert the changes for autoloading provided in 1.6.1 - [@dm1try](https://github.com/dm1try).
|
8
|
+
|
9
|
+
### 1.6.1 (2021/12/28)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* [#2196](https://github.com/ruby-grape/grape/pull/2196): Add support for `passwords_hashed` param for `digest_auth` - [@lHydra](https://github.com/lhydra).
|
14
|
+
* [#2208](https://github.com/ruby-grape/grape/pull/2208): Added Rails 7 support - [@ericproulx](https://github.com/ericproulx).
|
15
|
+
|
16
|
+
#### Fixes
|
17
|
+
|
18
|
+
* [#2206](https://github.com/ruby-grape/grape/pull/2206): Require main active_support lib before any of its extension definitions - [@annih](https://github.com/Annih).
|
19
|
+
* [#2193](https://github.com/ruby-grape/grape/pull/2193): Fixed the broken ruby-head NoMethodError spec - [@Jack12816](https://github.com/Jack12816).
|
20
|
+
* [#2192](https://github.com/ruby-grape/grape/pull/2192): Memoize the result of Grape::Middleware::Base#response - [@Jack12816](https://github.com/Jack12816).
|
21
|
+
* [#2200](https://github.com/ruby-grape/grape/pull/2200): Add validators module to all validators - [@ericproulx](https://github.com/ericproulx).
|
22
|
+
* [#2202](https://github.com/ruby-grape/grape/pull/2202): Fix random mock spec error - [@ericproulx](https://github.com/ericproulx).
|
23
|
+
* [#2203](https://github.com/ruby-grape/grape/pull/2203): Add rubocop-rspec - [@ericproulx](https://github.com/ericproulx).
|
24
|
+
* [#2207](https://github.com/ruby-grape/grape/pull/2207): Autoload Validations/Validators - [@ericproulx](https://github.com/ericproulx).
|
25
|
+
* [#2209](https://github.com/ruby-grape/grape/pull/2209): Autoload Validations/Types - [@ericproulx](https://github.com/ericproulx).
|
26
|
+
|
27
|
+
### 1.6.0 (2021/10/04)
|
28
|
+
|
29
|
+
#### Features
|
30
|
+
|
31
|
+
* [#2190](https://github.com/ruby-grape/grape/pull/2190): Upgrade dev deps & drop Ruby 2.4.x support - [@dnesteryuk](https://github.com/dnesteryuk).
|
32
|
+
|
33
|
+
#### Fixes
|
34
|
+
|
35
|
+
* [#2176](https://github.com/ruby-grape/grape/pull/2176): Fix: OPTIONS fails if matching all routes - [@myxoh](https://github.com/myxoh).
|
36
|
+
* [#2177](https://github.com/ruby-grape/grape/pull/2177): Fix: `default` validator fails if preceded by `as` validator - [@Catsuko](https://github.com/Catsuko).
|
37
|
+
* [#2180](https://github.com/ruby-grape/grape/pull/2180): Call `super` in `API.inherited` - [@yogeshjain999](https://github.com/yogeshjain999).
|
38
|
+
* [#2189](https://github.com/ruby-grape/grape/pull/2189): Fix: rename parameters when using `:as` (behaviour and grape-swagger documentation) - [@Jack12816](https://github.com/Jack12816).
|
39
|
+
|
40
|
+
### 1.5.3 (2021/03/07)
|
41
|
+
|
42
|
+
#### Fixes
|
43
|
+
|
44
|
+
* [#2161](https://github.com/ruby-grape/grape/pull/2157): Handle EOFError from Rack when given an empty multipart body - [@bschmeck](https://github.com/bschmeck).
|
45
|
+
* [#2162](https://github.com/ruby-grape/grape/pull/2162): Corrected a hash modification while iterating issue - [@Jack12816](https://github.com/Jack12816).
|
46
|
+
* [#2164](https://github.com/ruby-grape/grape/pull/2164): Fix: `coerce_with` is now called for params with `nil` value - [@braktar](https://github.com/braktar).
|
47
|
+
|
48
|
+
### 1.5.2 (2021/02/06)
|
49
|
+
|
50
|
+
#### Features
|
51
|
+
|
52
|
+
* [#2157](https://github.com/ruby-grape/grape/pull/2157): Custom types can set a message to be used in the response when invalid - [@dnesteryuk](https://github.com/dnesteryuk).
|
53
|
+
* [#2145](https://github.com/ruby-grape/grape/pull/2145): Ruby 3.0 compatibility - [@ericproulx](https://github.com/ericproulx).
|
54
|
+
* [#2143](https://github.com/ruby-grape/grape/pull/2143): Enable GitHub Actions with updated RuboCop and Danger - [@anakinj](https://github.com/anakinj).
|
55
|
+
|
56
|
+
#### Fixes
|
57
|
+
|
58
|
+
* [#2144](https://github.com/ruby-grape/grape/pull/2144): Fix compatibility issue with activesupport 6.1 and XML serialization of arrays - [@anakinj](https://github.com/anakinj).
|
59
|
+
* [#2137](https://github.com/ruby-grape/grape/pull/2137): Fix typos - [@johnny-miyake](https://github.com/johnny-miyake).
|
60
|
+
* [#2131](https://github.com/ruby-grape/grape/pull/2131): Fix Ruby 2.7 keyword deprecation warning in validators/coerce - [@K0H205](https://github.com/K0H205).
|
61
|
+
* [#2132](https://github.com/ruby-grape/grape/pull/2132): Use #ruby2_keywords for correct delegation on Ruby <= 2.6, 2.7 and 3 - [@eregon](https://github.com/eregon).
|
62
|
+
* [#2152](https://github.com/ruby-grape/grape/pull/2152): Fix configuration method inside namespaced params - [@fsainz](https://github.com/fsainz).
|
63
|
+
|
64
|
+
### 1.5.1 (2020/11/15)
|
65
|
+
|
66
|
+
#### Fixes
|
67
|
+
|
68
|
+
* [#2129](https://github.com/ruby-grape/grape/pull/2129): Fix validation error when Required Array nested inside an optional array, for Multiparam validators - [@dwhenry](https://github.com/dwhenry).
|
69
|
+
* [#2128](https://github.com/ruby-grape/grape/pull/2128): Fix validation error when Required Array nested inside an optional array - [@dwhenry](https://github.com/dwhenry).
|
70
|
+
* [#2127](https://github.com/ruby-grape/grape/pull/2127): Fix a performance issue with dependent params - [@dnesteryuk](https://github.com/dnesteryuk).
|
71
|
+
* [#2126](https://github.com/ruby-grape/grape/pull/2126): Fix warnings about redefined attribute accessors in `AttributeTranslator` - [@samsonjs](https://github.com/samsonjs).
|
72
|
+
* [#2121](https://github.com/ruby-grape/grape/pull/2121): Fix 2.7 deprecation warning in validator_factory - [@Legogris](https://github.com/Legogris).
|
73
|
+
* [#2115](https://github.com/ruby-grape/grape/pull/2115): Fix declared_params regression with multiple allowed types - [@stanhu](https://github.com/stanhu).
|
74
|
+
* [#2123](https://github.com/ruby-grape/grape/pull/2123): Fix 2.7 deprecation warning in middleware/stack - [@Legogris](https://github.com/Legogris).
|
75
|
+
|
76
|
+
### 1.5.0 (2020/10/05)
|
77
|
+
|
78
|
+
#### Fixes
|
79
|
+
|
80
|
+
* [#2104](https://github.com/ruby-grape/grape/pull/2104): Fix Ruby 2.7 keyword deprecation warning - [@stanhu](https://github.com/stanhu).
|
81
|
+
* [#2103](https://github.com/ruby-grape/grape/pull/2103): Ensure complete declared params structure is present - [@tlconnor](https://github.com/tlconnor).
|
82
|
+
* [#2099](https://github.com/ruby-grape/grape/pull/2099): Added truffleruby to Travis-CI - [@gogainda](https://github.com/gogainda).
|
83
|
+
* [#2089](https://github.com/ruby-grape/grape/pull/2089): Specify order of mounting Grape with Rack::Cascade in README - [@jonmchan](https://github.com/jonmchan).
|
84
|
+
* [#2088](https://github.com/ruby-grape/grape/pull/2088): Set `Cache-Control` header only for streamed responses - [@stanhu](https://github.com/stanhu).
|
85
|
+
* [#2092](https://github.com/ruby-grape/grape/pull/2092): Correct an example params in Include Missing doc - [@huyvohcmc](https://github.com/huyvohcmc).
|
86
|
+
* [#2091](https://github.com/ruby-grape/grape/pull/2091): Fix ruby 2.7 keyword deprecations - [@dim](https://github.com/dim).
|
87
|
+
* [#2097](https://github.com/ruby-grape/grape/pull/2097): Skip to set default value unless `meets_dependency?` - [@wanabe](https://github.com/wanabe).
|
88
|
+
* [#2096](https://github.com/ruby-grape/grape/pull/2096): Fix redundant dependency check - [@braktar](https://github.com/braktar).
|
89
|
+
* [#2096](https://github.com/ruby-grape/grape/pull/2098): Fix nested coercion - [@braktar](https://github.com/braktar).
|
90
|
+
* [#2102](https://github.com/ruby-grape/grape/pull/2102): Fix retaining setup blocks when remounting APIs - [@jylamont](https://github.com/jylamont).
|
91
|
+
|
92
|
+
### 1.4.0 (2020/07/10)
|
93
|
+
|
94
|
+
#### Features
|
95
|
+
|
96
|
+
* [#1520](https://github.com/ruby-grape/grape/pull/1520): Un-deprecate stream-like objects - [@urkle](https://github.com/urkle).
|
97
|
+
* [#2060](https://github.com/ruby-grape/grape/pull/2060): Drop support for Ruby 2.4 - [@dblock](https://github.com/dblock).
|
98
|
+
* [#2060](https://github.com/ruby-grape/grape/pull/2060): Upgraded Rubocop to 0.84.0 - [@dblock](https://github.com/dblock).
|
99
|
+
* [#2077](https://github.com/ruby-grape/grape/pull/2077): Simplify logic for defining declared params - [@dnesteryuk](https://github.com/dnesteryuk).
|
100
|
+
* [#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).
|
101
|
+
|
102
|
+
#### Fixes
|
103
|
+
|
104
|
+
* [#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).
|
105
|
+
* [#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).
|
106
|
+
* [#2072](https://github.com/ruby-grape/grape/pull/2072): Fix `Grape.eager_load!` and `compile!` - [@stanhu](https://github.com/stanhu).
|
107
|
+
* [#2084](https://github.com/ruby-grape/grape/pull/2084): Fix memory leak in path normalization - [@fcheung](https://github.com/fcheung).
|
108
|
+
|
1
109
|
### 1.3.3 (2020/05/23)
|
2
110
|
|
3
111
|
#### Features
|
@@ -52,7 +160,8 @@
|
|
52
160
|
* [#1976](https://github.com/ruby-grape/grape/pull/1976): Ensure classes/modules listed for autoload really exist - [@dnesteryuk](https://github.com/dnesteryuk).
|
53
161
|
* [#1971](https://github.com/ruby-grape/grape/pull/1971): Fix BigDecimal coercion - [@FlickStuart](https://github.com/FlickStuart).
|
54
162
|
* [#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).
|
55
|
-
* [#1988](https://github.com/ruby-grape/grape/pull/1988):
|
163
|
+
* [#1988](https://github.com/ruby-grape/grape/pull/1988): Refactor the full_messages method and stop overriding full_message - [@hosseintoussi](https://github.com/hosseintoussi).
|
164
|
+
* [#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).
|
56
165
|
|
57
166
|
### 1.3.0 (2020/01/11)
|
58
167
|
|
@@ -575,7 +684,7 @@
|
|
575
684
|
* [#492](https://github.com/ruby-grape/grape/pull/492): Don't allow to have nil value when a param is required and has a list of allowed values - [@Antti](https://github.com/Antti).
|
576
685
|
* [#495](https://github.com/ruby-grape/grape/pull/495): Fixed `ParamsScope#params` for parameters nested inside arrays - [@asross](https://github.com/asross).
|
577
686
|
* [#498](https://github.com/ruby-grape/grape/pull/498): Dry'ed up options and headers logic, allow headers to be passed to OPTIONS requests - [@karlfreeman](https://github.com/karlfreeman).
|
578
|
-
* [#500](https://github.com/ruby-grape/grape/pull/500): Skip entity auto-detection when
|
687
|
+
* [#500](https://github.com/ruby-grape/grape/pull/500): Skip entity auto-detection when explicitly passed - [@yaneq](https://github.com/yaneq).
|
579
688
|
* [#503](https://github.com/ruby-grape/grape/pull/503): Calling declared(params) from child namespace fails to include parent namespace defined params - [@myitcv](https://github.com/myitcv).
|
580
689
|
* [#512](https://github.com/ruby-grape/grape/pull/512): Don't create `Grape::Request` multiple times - [@dblock](https://github.com/dblock).
|
581
690
|
* [#538](https://github.com/ruby-grape/grape/pull/538): Fixed default values for grouped params - [@dm1try](https://github.com/dm1try).
|
data/CONTRIBUTING.md
CHANGED
@@ -35,6 +35,7 @@ bundle exec rake
|
|
35
35
|
Run tests against all supported versions of Rails.
|
36
36
|
|
37
37
|
```
|
38
|
+
gem install appraisal
|
38
39
|
appraisal install
|
39
40
|
appraisal rake spec
|
40
41
|
```
|
@@ -118,7 +119,7 @@ Go back to your pull request after a few minutes and see whether it passed muste
|
|
118
119
|
|
119
120
|
#### Be Patient
|
120
121
|
|
121
|
-
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang
|
122
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang in there!
|
122
123
|
|
123
124
|
#### Thank You
|
124
125
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
![grape logo](grape.png)
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/grape.svg)](http://badge.fury.io/rb/grape)
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/ruby-grape/grape/workflows/test/badge.svg?branch=master)](https://github.com/ruby-grape/grape/actions)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/ruby-grape/grape.svg)](https://codeclimate.com/github/ruby-grape/grape)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/github/ruby-grape/grape/badge.svg?branch=master)](https://coveralls.io/github/ruby-grape/grape?branch=master)
|
7
7
|
[![Inline docs](https://inch-ci.org/github/ruby-grape/grape.svg)](https://inch-ci.org/github/ruby-grape/grape)
|
@@ -19,6 +19,8 @@
|
|
19
19
|
- [All](#all)
|
20
20
|
- [Rack](#rack)
|
21
21
|
- [ActiveRecord without Rails](#activerecord-without-rails)
|
22
|
+
- [Rails 4](#rails-4)
|
23
|
+
- [Rails 5+](#rails-5)
|
22
24
|
- [Alongside Sinatra (or other frameworks)](#alongside-sinatra-or-other-frameworks)
|
23
25
|
- [Rails](#rails)
|
24
26
|
- [Rails < 5.2](#rails--52)
|
@@ -156,7 +158,8 @@ content negotiation, versioning and much more.
|
|
156
158
|
|
157
159
|
## Stable Release
|
158
160
|
|
159
|
-
You're reading the documentation for the stable release of Grape, **1.
|
161
|
+
You're reading the documentation for the stable release of Grape, **1.6.2**.
|
162
|
+
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
160
163
|
|
161
164
|
## Project Resources
|
162
165
|
|
@@ -315,13 +318,21 @@ Grape will also automatically respond to HEAD and OPTIONS for all GET, and just
|
|
315
318
|
If you want to use ActiveRecord within Grape, you will need to make sure that ActiveRecord's connection pool
|
316
319
|
is handled correctly.
|
317
320
|
|
321
|
+
#### Rails 4
|
322
|
+
|
318
323
|
The easiest way to achieve that is by using ActiveRecord's `ConnectionManagement` middleware in your
|
319
324
|
`config.ru` before mounting Grape, e.g.:
|
320
325
|
|
321
326
|
```ruby
|
322
327
|
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
328
|
+
```
|
323
329
|
|
324
|
-
|
330
|
+
#### Rails 5+
|
331
|
+
|
332
|
+
Use [otr-activerecord](https://github.com/jhollinger/otr-activerecord) as follows:
|
333
|
+
|
334
|
+
```ruby
|
335
|
+
use OTR::ActiveRecord::ConnectionManagement
|
325
336
|
```
|
326
337
|
|
327
338
|
### Alongside Sinatra (or other frameworks)
|
@@ -348,9 +359,12 @@ class Web < Sinatra::Base
|
|
348
359
|
end
|
349
360
|
|
350
361
|
use Rack::Session::Cookie
|
351
|
-
run Rack::Cascade.new [
|
362
|
+
run Rack::Cascade.new [Web, API]
|
352
363
|
```
|
353
364
|
|
365
|
+
Note that order of loading apps using `Rack::Cascade` matters. The grape application must be last if you want to raise custom 404 errors from grape (such as `error!('Not Found',404)`). If the grape application is not last and returns 404 or 405 response, [cascade utilizes that as a signal to try the next app](https://www.rubydoc.info/gems/rack/Rack/Cascade). This may lead to undesirable behavior showing the [wrong 404 page from the wrong app](https://github.com/ruby-grape/grape/issues/1515).
|
366
|
+
|
367
|
+
|
354
368
|
### Rails
|
355
369
|
|
356
370
|
Place API files into `app/api`. Rails expects a subdirectory that matches the name of the Ruby module and a file name that matches the name of the class. In our example, the file name location and directory for `Twitter::API` should be `app/api/twitter/api.rb`.
|
@@ -782,7 +796,13 @@ Available parameter builders are `Grape::Extensions::Hash::ParamBuilder`, `Grape
|
|
782
796
|
|
783
797
|
### Declared
|
784
798
|
|
785
|
-
Grape allows you to access only the parameters that have been declared by your `params` block. It
|
799
|
+
Grape allows you to access only the parameters that have been declared by your `params` block. It will:
|
800
|
+
|
801
|
+
* Filter out the params that have been passed, but are not allowed.
|
802
|
+
* Include any optional params that are declared but not passed.
|
803
|
+
* Perform any parameter renaming on the resulting hash.
|
804
|
+
|
805
|
+
Consider the following API endpoint:
|
786
806
|
|
787
807
|
````ruby
|
788
808
|
format :json
|
@@ -815,9 +835,9 @@ Once we add parameters requirements, grape will start returning only the declare
|
|
815
835
|
format :json
|
816
836
|
|
817
837
|
params do
|
818
|
-
|
819
|
-
|
820
|
-
|
838
|
+
optional :user, type: Hash do
|
839
|
+
optional :first_name, type: String
|
840
|
+
optional :last_name, type: String
|
821
841
|
end
|
822
842
|
end
|
823
843
|
|
@@ -845,6 +865,44 @@ curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d
|
|
845
865
|
}
|
846
866
|
````
|
847
867
|
|
868
|
+
Missing params that are declared as type `Hash` or `Array` will be included.
|
869
|
+
|
870
|
+
````ruby
|
871
|
+
format :json
|
872
|
+
|
873
|
+
params do
|
874
|
+
optional :user, type: Hash do
|
875
|
+
optional :first_name, type: String
|
876
|
+
optional :last_name, type: String
|
877
|
+
end
|
878
|
+
optional :widgets, type: Array
|
879
|
+
end
|
880
|
+
|
881
|
+
post 'users/signup' do
|
882
|
+
{ 'declared_params' => declared(params) }
|
883
|
+
end
|
884
|
+
````
|
885
|
+
|
886
|
+
**Request**
|
887
|
+
|
888
|
+
````bash
|
889
|
+
curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d '{}'
|
890
|
+
````
|
891
|
+
|
892
|
+
**Response**
|
893
|
+
|
894
|
+
````json
|
895
|
+
{
|
896
|
+
"declared_params": {
|
897
|
+
"user": {
|
898
|
+
"first_name": null,
|
899
|
+
"last_name": null
|
900
|
+
},
|
901
|
+
"widgets": []
|
902
|
+
}
|
903
|
+
}
|
904
|
+
````
|
905
|
+
|
848
906
|
The returned hash is an `ActiveSupport::HashWithIndifferentAccess`.
|
849
907
|
|
850
908
|
The `#declared` method is not available to `before` filters, as those are evaluated prior to parameter coercion.
|
@@ -903,8 +961,10 @@ By default `declared(params)` includes parameters that have `nil` values. If you
|
|
903
961
|
format :json
|
904
962
|
|
905
963
|
params do
|
906
|
-
requires :
|
907
|
-
|
964
|
+
requires :user, type: Hash do
|
965
|
+
requires :first_name, type: String
|
966
|
+
optional :last_name, type: String
|
967
|
+
end
|
908
968
|
end
|
909
969
|
|
910
970
|
post 'users/signup' do
|
@@ -935,8 +995,10 @@ curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d
|
|
935
995
|
````json
|
936
996
|
{
|
937
997
|
"declared_params": {
|
938
|
-
"
|
939
|
-
|
998
|
+
"user": {
|
999
|
+
"first_name": "first name",
|
1000
|
+
"last_name": null
|
1001
|
+
}
|
940
1002
|
}
|
941
1003
|
}
|
942
1004
|
````
|
@@ -1057,13 +1119,13 @@ params do
|
|
1057
1119
|
end
|
1058
1120
|
```
|
1059
1121
|
|
1060
|
-
Note that default values will be passed through to any validation options specified.
|
1061
|
-
The following example will always fail if `:color` is not explicitly provided.
|
1062
|
-
|
1063
1122
|
Default values are eagerly evaluated. Above `:non_random_number` will evaluate to the same
|
1064
1123
|
number for each call to the endpoint of this `params` block. To have the default evaluate
|
1065
1124
|
lazily with each request use a lambda, like `:random_number` above.
|
1066
1125
|
|
1126
|
+
Note that default values will be passed through to any validation options specified.
|
1127
|
+
The following example will always fail if `:color` is not explicitly provided.
|
1128
|
+
|
1067
1129
|
```ruby
|
1068
1130
|
params do
|
1069
1131
|
optional :color, type: String, default: 'blue', values: ['red', 'green']
|
@@ -1123,7 +1185,8 @@ Aside from the default set of supported types listed above, any class can be
|
|
1123
1185
|
used as a type as long as an explicit coercion method is supplied. If the type
|
1124
1186
|
implements a class-level `parse` method, Grape will use it automatically.
|
1125
1187
|
This method must take one string argument and return an instance of the correct
|
1126
|
-
type, or
|
1188
|
+
type, or return an instance of `Grape::Types::InvalidValue` which optionally
|
1189
|
+
accepts a message to be returned in the response.
|
1127
1190
|
|
1128
1191
|
```ruby
|
1129
1192
|
class Color
|
@@ -1133,8 +1196,9 @@ class Color
|
|
1133
1196
|
end
|
1134
1197
|
|
1135
1198
|
def self.parse(value)
|
1136
|
-
|
1137
|
-
|
1199
|
+
return new(value) if %w[blue red green]).include?(value)
|
1200
|
+
|
1201
|
+
Grape::Types::InvalidValue.new('Unsupported color')
|
1138
1202
|
end
|
1139
1203
|
end
|
1140
1204
|
|
@@ -1166,6 +1230,7 @@ params do
|
|
1166
1230
|
end
|
1167
1231
|
end
|
1168
1232
|
```
|
1233
|
+
Note that, a `nil` value will call the custom coercion method, while a missing parameter will not.
|
1169
1234
|
|
1170
1235
|
Example of use of `coerce_with` with a lambda (a class with a `parse` method could also have been used)
|
1171
1236
|
It will parse a string and return an Array of Integers, matching the `Array[Integer]` `type`.
|
@@ -1467,6 +1532,14 @@ end
|
|
1467
1532
|
|
1468
1533
|
While Procs are convenient for single cases, consider using [Custom Validators](#custom-validators) in cases where a validation is used more than once.
|
1469
1534
|
|
1535
|
+
Note that [allow_blank](#allow_blank) validator applies while using `:values`. In the following example the absence of `:allow_blank` does not prevent `:state` from receiving blank values because `:allow_blank` defaults to `true`.
|
1536
|
+
|
1537
|
+
```ruby
|
1538
|
+
params do
|
1539
|
+
requires :state, type: Symbol, values: [:active, :inactive]
|
1540
|
+
end
|
1541
|
+
```
|
1542
|
+
|
1470
1543
|
#### `except_values`
|
1471
1544
|
|
1472
1545
|
Parameters can be restricted from having a specific set of values with the `:except_values` option.
|
@@ -1990,10 +2063,10 @@ end
|
|
1990
2063
|
|
1991
2064
|
# is NOT the same as
|
1992
2065
|
|
1993
|
-
get ':status' do # this makes
|
2066
|
+
get ':status' do # this makes params[:status] available
|
1994
2067
|
end
|
1995
2068
|
|
1996
|
-
# This will make both
|
2069
|
+
# This will make both params[:status_id] and params[:id] available
|
1997
2070
|
|
1998
2071
|
get 'statuses/:status_id/reviews/:id' do
|
1999
2072
|
end
|
@@ -3166,17 +3239,19 @@ end
|
|
3166
3239
|
|
3167
3240
|
Use `body false` to return `204 No Content` without any data or content-type.
|
3168
3241
|
|
3169
|
-
You can also set the response to a file with `
|
3242
|
+
You can also set the response to a file with `sendfile`. This works with the
|
3243
|
+
[Rack::Sendfile](https://www.rubydoc.info/gems/rack/Rack/Sendfile) middleware to optimally send
|
3244
|
+
the file through your web server software.
|
3170
3245
|
|
3171
3246
|
```ruby
|
3172
3247
|
class API < Grape::API
|
3173
3248
|
get '/' do
|
3174
|
-
|
3249
|
+
sendfile '/path/to/file'
|
3175
3250
|
end
|
3176
3251
|
end
|
3177
3252
|
```
|
3178
3253
|
|
3179
|
-
|
3254
|
+
To stream a file in chunks use `stream`
|
3180
3255
|
|
3181
3256
|
```ruby
|
3182
3257
|
class API < Grape::API
|
@@ -3186,6 +3261,26 @@ class API < Grape::API
|
|
3186
3261
|
end
|
3187
3262
|
```
|
3188
3263
|
|
3264
|
+
If you want to stream non-file data use the `stream` method and a `Stream` object.
|
3265
|
+
This is an object that responds to `each` and yields for each chunk to send to the client.
|
3266
|
+
Each chunk will be sent as it is yielded instead of waiting for all of the content to be available.
|
3267
|
+
|
3268
|
+
```ruby
|
3269
|
+
class MyStream
|
3270
|
+
def each
|
3271
|
+
yield 'part 1'
|
3272
|
+
yield 'part 2'
|
3273
|
+
yield 'part 3'
|
3274
|
+
end
|
3275
|
+
end
|
3276
|
+
|
3277
|
+
class API < Grape::API
|
3278
|
+
get '/' do
|
3279
|
+
stream MyStream.new
|
3280
|
+
end
|
3281
|
+
end
|
3282
|
+
```
|
3283
|
+
|
3189
3284
|
## Authentication
|
3190
3285
|
|
3191
3286
|
### Basic and Digest Auth
|
@@ -3201,12 +3296,20 @@ http_basic do |username, password|
|
|
3201
3296
|
end
|
3202
3297
|
```
|
3203
3298
|
|
3299
|
+
Digest auth supports clear-text passwords and password hashes.
|
3300
|
+
|
3204
3301
|
```ruby
|
3205
3302
|
http_digest({ realm: 'Test Api', opaque: 'app secret' }) do |username|
|
3206
3303
|
# lookup the user's password here
|
3207
3304
|
end
|
3208
3305
|
```
|
3209
3306
|
|
3307
|
+
```ruby
|
3308
|
+
http_digest(realm: { realm: 'Test Api', opaque: 'app secret', passwords_hashed: true }) do |username|
|
3309
|
+
# lookup the user's password hash here
|
3310
|
+
end
|
3311
|
+
```
|
3312
|
+
|
3210
3313
|
### Register custom middleware for authentication
|
3211
3314
|
|
3212
3315
|
Grape can use custom Middleware for authentication. How to implement these
|
@@ -3557,6 +3660,14 @@ You can access the controller params, headers, and helpers through the context w
|
|
3557
3660
|
Note that when you're using Grape mounted on Rails you don't have to use Rails middleware because it's already included into your middleware stack.
|
3558
3661
|
You only have to implement the helpers to access the specific `env` variable.
|
3559
3662
|
|
3663
|
+
If you are using a custom application that is inherited from `Rails::Application` and need to insert a new middleware among the ones initiated via Rails, you will need to register it manually in your custom application class.
|
3664
|
+
|
3665
|
+
```ruby
|
3666
|
+
class Company::Application < Rails::Application
|
3667
|
+
config.middleware.insert_before(Rack::Attack, Middleware::ApiLogger)
|
3668
|
+
end
|
3669
|
+
```
|
3670
|
+
|
3560
3671
|
### Remote IP
|
3561
3672
|
|
3562
3673
|
By default you can access remote IP with `request.ip`. This is the remote IP address implemented by Rack. Sometimes it is desirable to get the remote IP [Rails-style](http://stackoverflow.com/questions/10997005/whats-the-difference-between-request-remote-ip-and-request-ip-in-rails) with `ActionDispatch::RemoteIp`.
|
@@ -3861,6 +3972,7 @@ Grape integrates with following third-party tools:
|
|
3861
3972
|
* **[Skylight](https://www.skylight.io/)** - [skylight](https://github.com/skylightio/skylight-ruby) gem, [documentation](https://docs.skylight.io/grape/)
|
3862
3973
|
* **[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)
|
3863
3974
|
* **[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)
|
3975
|
+
* **[Datadog APM](https://docs.datadoghq.com/tracing/)** - [ddtrace](https://github.com/datadog/dd-trace-rb) gem, [documentation](https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#grape)
|
3864
3976
|
|
3865
3977
|
## Contributing to Grape
|
3866
3978
|
|