grape 1.5.3 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -0
  3. data/CONTRIBUTING.md +32 -1
  4. data/README.md +176 -25
  5. data/UPGRADING.md +61 -4
  6. data/grape.gemspec +6 -6
  7. data/lib/grape/api/instance.rb +14 -18
  8. data/lib/grape/api.rb +17 -12
  9. data/lib/grape/cookies.rb +2 -0
  10. data/lib/grape/dry_types.rb +12 -0
  11. data/lib/grape/dsl/api.rb +0 -2
  12. data/lib/grape/dsl/callbacks.rb +0 -2
  13. data/lib/grape/dsl/configuration.rb +0 -2
  14. data/lib/grape/dsl/desc.rb +4 -20
  15. data/lib/grape/dsl/headers.rb +5 -2
  16. data/lib/grape/dsl/helpers.rb +7 -7
  17. data/lib/grape/dsl/inside_route.rb +43 -30
  18. data/lib/grape/dsl/middleware.rb +4 -6
  19. data/lib/grape/dsl/parameters.rb +13 -10
  20. data/lib/grape/dsl/request_response.rb +9 -8
  21. data/lib/grape/dsl/routing.rb +6 -4
  22. data/lib/grape/dsl/settings.rb +5 -7
  23. data/lib/grape/dsl/validations.rb +0 -15
  24. data/lib/grape/endpoint.rb +22 -37
  25. data/lib/grape/error_formatter/json.rb +9 -7
  26. data/lib/grape/error_formatter/xml.rb +2 -6
  27. data/lib/grape/exceptions/base.rb +3 -2
  28. data/lib/grape/exceptions/missing_group_type.rb +8 -1
  29. data/lib/grape/exceptions/too_many_multipart_files.rb +11 -0
  30. data/lib/grape/exceptions/unsupported_group_type.rb +8 -1
  31. data/lib/grape/exceptions/validation.rb +1 -6
  32. data/lib/grape/formatter/json.rb +1 -0
  33. data/lib/grape/formatter/serializable_hash.rb +2 -1
  34. data/lib/grape/formatter/xml.rb +1 -0
  35. data/lib/grape/locale/en.yml +9 -8
  36. data/lib/grape/middleware/auth/dsl.rb +7 -2
  37. data/lib/grape/middleware/base.rb +3 -1
  38. data/lib/grape/middleware/error.rb +2 -2
  39. data/lib/grape/middleware/formatter.rb +4 -4
  40. data/lib/grape/middleware/stack.rb +3 -3
  41. data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
  42. data/lib/grape/middleware/versioner/header.rb +6 -4
  43. data/lib/grape/middleware/versioner/param.rb +1 -0
  44. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
  45. data/lib/grape/middleware/versioner/path.rb +2 -0
  46. data/lib/grape/path.rb +1 -0
  47. data/lib/grape/request.rb +4 -1
  48. data/lib/grape/router/attribute_translator.rb +1 -1
  49. data/lib/grape/router/pattern.rb +1 -1
  50. data/lib/grape/router/route.rb +2 -2
  51. data/lib/grape/router.rb +6 -0
  52. data/lib/grape/types/invalid_value.rb +8 -0
  53. data/lib/grape/util/cache.rb +1 -1
  54. data/lib/grape/util/inheritable_setting.rb +1 -3
  55. data/lib/grape/util/json.rb +2 -0
  56. data/lib/grape/util/lazy_value.rb +3 -2
  57. data/lib/grape/util/strict_hash_configuration.rb +1 -1
  58. data/lib/grape/validations/attributes_doc.rb +58 -0
  59. data/lib/grape/validations/params_scope.rb +138 -79
  60. data/lib/grape/validations/types/array_coercer.rb +0 -2
  61. data/lib/grape/validations/types/custom_type_coercer.rb +1 -0
  62. data/lib/grape/validations/types/dry_type_coercer.rb +4 -8
  63. data/lib/grape/validations/types/invalid_value.rb +0 -7
  64. data/lib/grape/validations/types/json.rb +2 -1
  65. data/lib/grape/validations/types/primitive_coercer.rb +16 -8
  66. data/lib/grape/validations/types/set_coercer.rb +0 -2
  67. data/lib/grape/validations/types.rb +98 -30
  68. data/lib/grape/validations/validators/all_or_none_of_validator.rb +16 -0
  69. data/lib/grape/validations/validators/allow_blank_validator.rb +20 -0
  70. data/lib/grape/validations/validators/as_validator.rb +14 -0
  71. data/lib/grape/validations/validators/at_least_one_of_validator.rb +15 -0
  72. data/lib/grape/validations/validators/base.rb +82 -70
  73. data/lib/grape/validations/validators/coerce_validator.rb +75 -0
  74. data/lib/grape/validations/validators/default_validator.rb +51 -0
  75. data/lib/grape/validations/validators/exactly_one_of_validator.rb +17 -0
  76. data/lib/grape/validations/validators/except_values_validator.rb +24 -0
  77. data/lib/grape/validations/validators/multiple_params_base.rb +24 -20
  78. data/lib/grape/validations/validators/mutual_exclusion_validator.rb +16 -0
  79. data/lib/grape/validations/validators/presence_validator.rb +15 -0
  80. data/lib/grape/validations/validators/regexp_validator.rb +16 -0
  81. data/lib/grape/validations/validators/same_as_validator.rb +29 -0
  82. data/lib/grape/validations/validators/values_validator.rb +88 -0
  83. data/lib/grape/validations.rb +16 -6
  84. data/lib/grape/version.rb +1 -1
  85. data/lib/grape.rb +77 -29
  86. data/spec/grape/api/custom_validations_spec.rb +116 -45
  87. data/spec/grape/api/deeply_included_options_spec.rb +3 -5
  88. data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -3
  89. data/spec/grape/api/documentation_spec.rb +59 -0
  90. data/spec/grape/api/inherited_helpers_spec.rb +0 -2
  91. data/spec/grape/api/instance_spec.rb +0 -1
  92. data/spec/grape/api/invalid_format_spec.rb +2 -2
  93. data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -2
  94. data/spec/grape/api/nested_helpers_spec.rb +0 -2
  95. data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -2
  96. data/spec/grape/api/parameters_modification_spec.rb +0 -2
  97. data/spec/grape/api/patch_method_helpers_spec.rb +0 -2
  98. data/spec/grape/api/recognize_path_spec.rb +1 -3
  99. data/spec/grape/api/required_parameters_in_route_spec.rb +0 -2
  100. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -2
  101. data/spec/grape/api/routes_with_requirements_spec.rb +8 -10
  102. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -17
  103. data/spec/grape/api/shared_helpers_spec.rb +0 -2
  104. data/spec/grape/api_remount_spec.rb +16 -16
  105. data/spec/grape/api_spec.rb +462 -251
  106. data/spec/grape/config_spec.rb +0 -2
  107. data/spec/grape/dsl/callbacks_spec.rb +2 -3
  108. data/spec/grape/dsl/desc_spec.rb +2 -2
  109. data/spec/grape/dsl/headers_spec.rb +39 -11
  110. data/spec/grape/dsl/helpers_spec.rb +3 -4
  111. data/spec/grape/dsl/inside_route_spec.rb +16 -16
  112. data/spec/grape/dsl/logger_spec.rb +15 -19
  113. data/spec/grape/dsl/middleware_spec.rb +2 -3
  114. data/spec/grape/dsl/parameters_spec.rb +2 -2
  115. data/spec/grape/dsl/request_response_spec.rb +7 -8
  116. data/spec/grape/dsl/routing_spec.rb +11 -10
  117. data/spec/grape/dsl/settings_spec.rb +0 -2
  118. data/spec/grape/dsl/validations_spec.rb +0 -17
  119. data/spec/grape/endpoint/declared_spec.rb +261 -16
  120. data/spec/grape/endpoint_spec.rb +88 -59
  121. data/spec/grape/entity_spec.rb +22 -23
  122. data/spec/grape/exceptions/base_spec.rb +16 -2
  123. data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -2
  124. data/spec/grape/exceptions/invalid_accept_header_spec.rb +64 -24
  125. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -2
  126. data/spec/grape/exceptions/invalid_response_spec.rb +0 -2
  127. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -3
  128. data/spec/grape/exceptions/missing_group_type_spec.rb +21 -0
  129. data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -2
  130. data/spec/grape/exceptions/missing_option_spec.rb +1 -3
  131. data/spec/grape/exceptions/unknown_options_spec.rb +0 -2
  132. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -2
  133. data/spec/grape/exceptions/unsupported_group_type_spec.rb +23 -0
  134. data/spec/grape/exceptions/validation_errors_spec.rb +13 -11
  135. data/spec/grape/exceptions/validation_spec.rb +5 -5
  136. data/spec/grape/extensions/param_builders/hash_spec.rb +7 -9
  137. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -10
  138. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -10
  139. data/spec/grape/integration/global_namespace_function_spec.rb +0 -2
  140. data/spec/grape/integration/rack_sendfile_spec.rb +1 -3
  141. data/spec/grape/integration/rack_spec.rb +6 -7
  142. data/spec/grape/loading_spec.rb +8 -10
  143. data/spec/grape/middleware/auth/base_spec.rb +0 -1
  144. data/spec/grape/middleware/auth/dsl_spec.rb +15 -8
  145. data/spec/grape/middleware/auth/strategies_spec.rb +60 -22
  146. data/spec/grape/middleware/base_spec.rb +28 -19
  147. data/spec/grape/middleware/error_spec.rb +8 -3
  148. data/spec/grape/middleware/exception_spec.rb +111 -163
  149. data/spec/grape/middleware/formatter_spec.rb +33 -14
  150. data/spec/grape/middleware/globals_spec.rb +7 -6
  151. data/spec/grape/middleware/stack_spec.rb +14 -14
  152. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -3
  153. data/spec/grape/middleware/versioner/header_spec.rb +30 -15
  154. data/spec/grape/middleware/versioner/param_spec.rb +7 -3
  155. data/spec/grape/middleware/versioner/path_spec.rb +5 -3
  156. data/spec/grape/middleware/versioner_spec.rb +1 -3
  157. data/spec/grape/named_api_spec.rb +0 -2
  158. data/spec/grape/parser_spec.rb +4 -2
  159. data/spec/grape/path_spec.rb +52 -54
  160. data/spec/grape/presenters/presenter_spec.rb +7 -8
  161. data/spec/grape/request_spec.rb +6 -6
  162. data/spec/grape/util/inheritable_setting_spec.rb +7 -8
  163. data/spec/grape/util/inheritable_values_spec.rb +3 -3
  164. data/spec/grape/util/reverse_stackable_values_spec.rb +3 -2
  165. data/spec/grape/util/stackable_values_spec.rb +7 -6
  166. data/spec/grape/util/strict_hash_configuration_spec.rb +0 -1
  167. data/spec/grape/validations/attributes_doc_spec.rb +153 -0
  168. data/spec/grape/validations/instance_behaivour_spec.rb +9 -12
  169. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +1 -2
  170. data/spec/grape/validations/params_scope_spec.rb +361 -96
  171. data/spec/grape/validations/single_attribute_iterator_spec.rb +2 -3
  172. data/spec/grape/validations/types/array_coercer_spec.rb +0 -2
  173. data/spec/grape/validations/types/primitive_coercer_spec.rb +24 -9
  174. data/spec/grape/validations/types/set_coercer_spec.rb +0 -2
  175. data/spec/grape/validations/types_spec.rb +36 -10
  176. data/spec/grape/validations/validators/all_or_none_spec.rb +50 -58
  177. data/spec/grape/validations/validators/allow_blank_spec.rb +135 -141
  178. data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -58
  179. data/spec/grape/validations/validators/coerce_spec.rb +23 -24
  180. data/spec/grape/validations/validators/default_spec.rb +72 -80
  181. data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -79
  182. data/spec/grape/validations/validators/except_values_spec.rb +3 -5
  183. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -79
  184. data/spec/grape/validations/validators/presence_spec.rb +16 -3
  185. data/spec/grape/validations/validators/regexp_spec.rb +25 -33
  186. data/spec/grape/validations/validators/same_as_spec.rb +14 -22
  187. data/spec/grape/validations/validators/values_spec.rb +201 -179
  188. data/spec/grape/validations_spec.rb +171 -79
  189. data/spec/integration/eager_load/eager_load_spec.rb +2 -2
  190. data/spec/integration/multi_json/json_spec.rb +1 -3
  191. data/spec/integration/multi_xml/xml_spec.rb +1 -3
  192. data/spec/shared/versioning_examples.rb +12 -9
  193. data/spec/spec_helper.rb +21 -6
  194. data/spec/support/basic_auth_encode_helpers.rb +1 -1
  195. metadata +41 -29
  196. data/lib/grape/validations/validators/all_or_none.rb +0 -15
  197. data/lib/grape/validations/validators/allow_blank.rb +0 -18
  198. data/lib/grape/validations/validators/as.rb +0 -16
  199. data/lib/grape/validations/validators/at_least_one_of.rb +0 -14
  200. data/lib/grape/validations/validators/coerce.rb +0 -91
  201. data/lib/grape/validations/validators/default.rb +0 -48
  202. data/lib/grape/validations/validators/exactly_one_of.rb +0 -16
  203. data/lib/grape/validations/validators/except_values.rb +0 -22
  204. data/lib/grape/validations/validators/mutual_exclusion.rb +0 -15
  205. data/lib/grape/validations/validators/presence.rb +0 -12
  206. data/lib/grape/validations/validators/regexp.rb +0 -13
  207. data/lib/grape/validations/validators/same_as.rb +0 -26
  208. data/lib/grape/validations/validators/values.rb +0 -83
  209. data/spec/grape/dsl/configuration_spec.rb +0 -16
  210. data/spec/grape/validations/attributes_iterator_spec.rb +0 -6
  211. data/spec/support/eager_load.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bda9361933fff7f38c7b6e6f5196d1b245336179a527addf3bfd3aa67c6ec544
4
- data.tar.gz: 71a93ff4542fe59fb985ab0cfba591267b9901171e293988020df381d5377504
3
+ metadata.gz: 40277732454d8810e4e96f638da9e6bd4ab818e39ac9c30788791cb4bd429871
4
+ data.tar.gz: b075dd96ba3dda6fcd05e6b1c126255b5e206b2d6bb9bf9b52f9cd6ec25a6efc
5
5
  SHA512:
6
- metadata.gz: c54f78461188735df911a7463b3b4a15f0257d071ac8ca43b5e8539d7bce1098a4383b85b480eced6d3e60cef204e4d7405edf17b3ccdb13d30e3fefb9011ba1
7
- data.tar.gz: e4051ac3c062e2972fb40f22cd95a6d902416b53422450dccef62e94ff20b2f447b86b4ef2d4596d69597da531446e735e53d50faeb0a6ab60996a584991950d
6
+ metadata.gz: 61d1ef36c90927e08119b6abf57b87fc5317b7b4ac73587d14bc23c9b671e0e76930b89b22d15ec806861f2c60c582647a4f95bc6a1100dca07066be1853d4e6
7
+ data.tar.gz: 42a4595d466b2092759dee55ad467a6733e29912b0faaf3abe203c18ab1c84b53b6a1d45868102ac16e6b431254664a6762b3ec0b8e52217c777f99adcf965cc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,95 @@
1
+ ### 1.7.1 (2023/05/14)
2
+
3
+ #### Features
4
+
5
+ * [#2288](https://github.com/ruby-grape/grape/pull/2288): Droped support for Ruby 2.5 - [@ericproulx](https://github.com/ericproulx).
6
+ * [#2288](https://github.com/ruby-grape/grape/pull/2288): Updated rubocop to 1.41.0 - [@ericproulx](https://github.com/ericproulx).
7
+ * [#2296](https://github.com/ruby-grape/grape/pull/2296): Fix cops and enables some - [@ericproulx](https://github.com/ericproulx).
8
+ * [#2302](https://github.com/ruby-grape/grape/pull/2302): Rack < 3 and update rack-test - [@ericproulx](https://github.com/ericproulx).
9
+ * [#2303](https://github.com/ruby-grape/grape/pull/2302): Rack >= 1.3.0 - [@ericproulx](https://github.com/ericproulx).
10
+ * [#2301](https://github.com/ruby-grape/grape/pull/2301): Revisit GH workflows - [@ericproulx](https://github.com/ericproulx).
11
+ * [#2311](https://github.com/ruby-grape/grape/pull/2311): Fix tests by pinning rack-test to < 2.1 - [@duffn](https://github.com/duffn).
12
+ * [#2310](https://github.com/ruby-grape/grape/pull/2310): Fix YARD docs markdown rendering - [@duffn](https://github.com/duffn).
13
+ * [#2317](https://github.com/ruby-grape/grape/pull/2317): Remove maruku and rubocop-ast as direct development/testing dependencies - [@ericproulx](https://github.com/ericproulx).
14
+ * [#2292](https://github.com/ruby-grape/grape/pull/2292): Introduce Docker to local development - [@ericproulx](https://github.com/ericproulx).
15
+ * [#2325](https://github.com/ruby-grape/grape/pull/2325): Change edge test workflows only run on demand - [@dblock](https://github.com/dblock).
16
+ * [#2324](https://github.com/ruby-grape/grape/pull/2324): Expose default in the description dsl - [@dhruvCW](https://github.com/dhruvCW).
17
+
18
+ #### Fixes
19
+
20
+ * [#2299](https://github.com/ruby-grape/grape/pull/2299): Fix, do not use kwargs for empty args - [@dm1try](https://github.com/dm1try).
21
+ * [#2307](https://github.com/ruby-grape/grape/pull/2307): Fixed autoloading of InvalidValue - [@fixlr](https://github.com/fixlr).
22
+ * [#2315](https://github.com/ruby-grape/grape/pull/2315): Update rspec - [@ericproulx](https://github.com/ericproulx).
23
+ * [#2319](https://github.com/ruby-grape/grape/pull/2319): Update rubocop - [@ericproulx](https://github.com/ericproulx).
24
+ * [#2323](https://github.com/ruby-grape/grape/pull/2323): Fix using endless ranges for values parameter - [@dhruvCW](https://github.com/dhruvCW).
25
+
26
+ ### 1.7.0 (2022/12/20)
27
+
28
+ #### Features
29
+
30
+ * [#2233](https://github.com/ruby-grape/grape/pull/2233): Added `do_not_document!` for disabling documentation to internal APIs - [@dnesteryuk](https://github.com/dnesteryuk).
31
+ * [#2235](https://github.com/ruby-grape/grape/pull/2235): Add support for Ruby 3.1 - [@petergoldstein](https://github.com/petergoldstein).
32
+ * [#2248](https://github.com/ruby-grape/grape/pull/2248): Upgraded to rspec 3.11.0 - [@dblock](https://github.com/dblock).
33
+ * [#2249](https://github.com/ruby-grape/grape/pull/2249): Split CI matrix, extract edge - [@dblock](https://github.com/dblock).
34
+ * [#2249](https://github.com/ruby-grape/grape/pull/2251): Upgraded to RuboCop 1.25.1 - [@dblock](https://github.com/dblock).
35
+ * [#2271](https://github.com/ruby-grape/grape/pull/2271): Fixed validation regression on Numeric type introduced in 1.3 - [@vasfed](https://github.com/Vasfed).
36
+ * [#2267](https://github.com/ruby-grape/grape/pull/2267): Standardized English error messages - [@dblock](https://github.com/dblock).
37
+ * [#2272](https://github.com/ruby-grape/grape/pull/2272): Added error on param init when provided type does not have `[]` coercion method, previously validation silently failed for any value - [@vasfed](https://github.com/Vasfed).
38
+ * [#2274](https://github.com/ruby-grape/grape/pull/2274): Error middleware support using rack util's symbols as status - [@dhruvCW](https://github.com/dhruvCW).
39
+ * [#2276](https://github.com/ruby-grape/grape/pull/2276): Fix exception super - [@ericproulx](https://github.com/ericproulx).
40
+ * [#2285](https://github.com/ruby-grape/grape/pull/2285), [#2287](https://github.com/ruby-grape/grape/pull/2287): Added :evaluate_given to declared(params) - [@zysend](https://github.com/zysend).
41
+
42
+ #### Fixes
43
+
44
+ * [#2263](https://github.com/ruby-grape/grape/pull/2263): Explicitly require `bigdecimal` and `date` - [@dblock](https://github.com/dblock).
45
+ * [#2222](https://github.com/ruby-grape/grape/pull/2222): Autoload types and validators - [@ericproulx](https://github.com/ericproulx).
46
+ * [#2232](https://github.com/ruby-grape/grape/pull/2232): Fix kwargs support in shared params definition - [@dm1try](https://github.com/dm1try).
47
+ * [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
48
+ * [#2234](https://github.com/ruby-grape/grape/pull/2234): Remove non-UTF8 characters from format before generating JSON error - [@bschmeck](https://github.com/bschmeck).
49
+ * [#2227](https://github.com/ruby-grape/grape/pull/2222): Rename `MissingGroupType` and `UnsupportedGroupType` exceptions - [@ericproulx](https://github.com/ericproulx).
50
+ * [#2244](https://github.com/ruby-grape/grape/pull/2244): Fix a breaking change in `Grape::Validations` provided in 1.6.1 - [@dm1try](https://github.com/dm1try).
51
+ * [#2250](https://github.com/ruby-grape/grape/pull/2250): Add deprecation warning for `UnsupportedGroupTypeError` and `MissingGroupTypeError` - [@ericproulx](https://github.com/ericproulx).
52
+ * [#2256](https://github.com/ruby-grape/grape/pull/2256): Raise `Grape::Exceptions::MultipartPartLimitError` from Rack when too many files are uploaded - [@bschmeck](https://github.com/bschmeck).
53
+ * [#2266](https://github.com/ruby-grape/grape/pull/2266): Fix code coverage - [@duffn](https://github.com/duffn).
54
+ * [#2284](https://github.com/ruby-grape/grape/pull/2284): Fix an unexpected backtick - [@zysend](https://github.com/zysend).
55
+
56
+ ### 1.6.2 (2021/12/30)
57
+
58
+ #### Fixes
59
+
60
+ * [#2219](https://github.com/ruby-grape/grape/pull/2219): Revert the changes for autoloading provided in 1.6.1 - [@dm1try](https://github.com/dm1try).
61
+
62
+ ### 1.6.1 (2021/12/28)
63
+
64
+ #### Features
65
+
66
+ * [#2196](https://github.com/ruby-grape/grape/pull/2196): Add support for `passwords_hashed` param for `digest_auth` - [@lHydra](https://github.com/lhydra).
67
+ * [#2208](https://github.com/ruby-grape/grape/pull/2208): Added Rails 7 support - [@ericproulx](https://github.com/ericproulx).
68
+
69
+ #### Fixes
70
+
71
+ * [#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).
72
+ * [#2193](https://github.com/ruby-grape/grape/pull/2193): Fixed the broken ruby-head NoMethodError spec - [@Jack12816](https://github.com/Jack12816).
73
+ * [#2192](https://github.com/ruby-grape/grape/pull/2192): Memoize the result of Grape::Middleware::Base#response - [@Jack12816](https://github.com/Jack12816).
74
+ * [#2200](https://github.com/ruby-grape/grape/pull/2200): Add validators module to all validators - [@ericproulx](https://github.com/ericproulx).
75
+ * [#2202](https://github.com/ruby-grape/grape/pull/2202): Fix random mock spec error - [@ericproulx](https://github.com/ericproulx).
76
+ * [#2203](https://github.com/ruby-grape/grape/pull/2203): Add rubocop-rspec - [@ericproulx](https://github.com/ericproulx).
77
+ * [#2207](https://github.com/ruby-grape/grape/pull/2207): Autoload Validations/Validators - [@ericproulx](https://github.com/ericproulx).
78
+ * [#2209](https://github.com/ruby-grape/grape/pull/2209): Autoload Validations/Types - [@ericproulx](https://github.com/ericproulx).
79
+
80
+ ### 1.6.0 (2021/10/04)
81
+
82
+ #### Features
83
+
84
+ * [#2190](https://github.com/ruby-grape/grape/pull/2190): Upgrade dev deps & drop Ruby 2.4.x support - [@dnesteryuk](https://github.com/dnesteryuk).
85
+
86
+ #### Fixes
87
+
88
+ * [#2176](https://github.com/ruby-grape/grape/pull/2176): Fix: OPTIONS fails if matching all routes - [@myxoh](https://github.com/myxoh).
89
+ * [#2177](https://github.com/ruby-grape/grape/pull/2177): Fix: `default` validator fails if preceded by `as` validator - [@Catsuko](https://github.com/Catsuko).
90
+ * [#2180](https://github.com/ruby-grape/grape/pull/2180): Call `super` in `API.inherited` - [@yogeshjain999](https://github.com/yogeshjain999).
91
+ * [#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).
92
+
1
93
  ### 1.5.3 (2021/03/07)
2
94
 
3
95
  #### Fixes
data/CONTRIBUTING.md CHANGED
@@ -23,6 +23,34 @@ git pull upstream master
23
23
  git checkout -b my-feature-branch
24
24
  ```
25
25
 
26
+ ### Docker
27
+
28
+ If you're familiar with [Docker](https://www.docker.com/), you can run everything through the following command:
29
+
30
+ ```
31
+ docker-compose run --rm --build grape <command_and_parameters>
32
+ ```
33
+
34
+ About the execution process:
35
+ - displays Ruby, Rubygems, Bundle and Gemfile version when starting:
36
+ ```
37
+ ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux-musl]
38
+ rubygems 3.4.12
39
+ Bundler version 2.4.1 (2022-12-24 commit f3175f033c)
40
+ Running default Gemfile
41
+ ```
42
+ - keeps the gems to the latest possible version
43
+ - executes under `bundle exec`
44
+
45
+ Here are some examples:
46
+
47
+ - running all specs `docker-compose run --rm --build grape rspec`
48
+ - running rspec on a specific file `docker-compose run --rm --build grape rspec spec/:file_path`
49
+ - running task `docker-compose run --rm --build grape rake <task_name>`
50
+ - running rubocop `docker-compose run --rm --build grape rubocop`
51
+ - running all specs on a specific ruby version (e.g 2.7.7) `RUBY_VERSION=2.7.7 docker-compose run --rm --build grape rspec`
52
+ - running specs on a specific gemfile (e.g rails_7_0.gemfile) `docker-compose run -e GEMFILE=rails_7_0 --rm --build grape rspec`
53
+
26
54
  #### Bundle Install and Test
27
55
 
28
56
  Ensure that you can build the project and run tests.
@@ -35,6 +63,7 @@ bundle exec rake
35
63
  Run tests against all supported versions of Rails.
36
64
 
37
65
  ```
66
+ gem install appraisal
38
67
  appraisal install
39
68
  appraisal rake spec
40
69
  ```
@@ -57,6 +86,8 @@ Make sure that `bundle exec rake` completes without errors.
57
86
 
58
87
  Document any external behavior in the [README](README.md).
59
88
 
89
+ You should also document code as necessary, using current code as examples. This project uses [YARD](https://yardoc.org/). You can run and preview the docs locally by [installing `yard`](https://yardoc.org/), running `yard server --reload` and view the docs at http://localhost:8808.
90
+
60
91
  #### Update Changelog
61
92
 
62
93
  Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
@@ -118,7 +149,7 @@ Go back to your pull request after a few minutes and see whether it passed muste
118
149
 
119
150
  #### Be Patient
120
151
 
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 on there!
152
+ 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
153
 
123
154
  #### Thank You
124
155
 
data/README.md CHANGED
@@ -40,6 +40,7 @@
40
40
  - [Declared](#declared)
41
41
  - [Include Parent Namespaces](#include-parent-namespaces)
42
42
  - [Include Missing](#include-missing)
43
+ - [Evaluate Given](#evaluate-given)
43
44
  - [Parameter Validation and Coercion](#parameter-validation-and-coercion)
44
45
  - [Supported Parameter Types](#supported-parameter-types)
45
46
  - [Integer/Fixnum and Coercions](#integerfixnum-and-coercions)
@@ -158,7 +159,7 @@ content negotiation, versioning and much more.
158
159
 
159
160
  ## Stable Release
160
161
 
161
- You're reading the documentation for the stable release of Grape, **v1.5.3**.
162
+ You're reading the documentation for the stable release of Grape, 1.7.1.
162
163
  Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
163
164
 
164
165
  ## Project Resources
@@ -174,21 +175,13 @@ Available as part of the Tidelift Subscription.
174
175
 
175
176
  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.
176
177
 
177
- In 2020, we plan to use the money towards gathering Grape contributors for dinner in New York City.
178
-
179
178
  ## Installation
180
179
 
181
180
  Ruby 2.4 or newer is required.
182
181
 
183
- Grape is available as a gem, to install it just install the gem:
184
-
185
- gem install grape
186
-
187
- If you're using Bundler, add the gem to Gemfile.
188
-
189
- gem 'grape'
182
+ Grape is available as a gem, to install it run:
190
183
 
191
- Run `bundle install`.
184
+ bundle add grape
192
185
 
193
186
  ## Basic Usage
194
187
 
@@ -545,12 +538,12 @@ end
545
538
 
546
539
  class V1 < Grape::API
547
540
  version 'v1'
548
- mount BasicAPI, with: { entity: mounted { configuration[:entity] || API::Enitities::Status } }
541
+ mount BasicAPI, with: { entity: mounted { configuration[:entity] || API::Entities::Status } }
549
542
  end
550
543
 
551
544
  class V2 < Grape::API
552
545
  version 'v2'
553
- mount BasicAPI, with: { entity: mounted { configuration[:entity] || API::Enitities::V2::Status } }
546
+ mount BasicAPI, with: { entity: mounted { configuration[:entity] || API::Entities::V2::Status } }
554
547
  end
555
548
  ```
556
549
 
@@ -645,6 +638,7 @@ desc 'Returns your public timeline.' do
645
638
  params API::Entities::Status.documentation
646
639
  success API::Entities::Entity
647
640
  failure [[401, 'Unauthorized', 'Entities::Error']]
641
+ default { code: 500, message: 'InvalidRequest', model: Entities::Error }
648
642
  named 'My named route'
649
643
  headers XAuthToken: {
650
644
  description: 'Validates your identity',
@@ -669,8 +663,9 @@ end
669
663
 
670
664
  * `detail`: A more enhanced description
671
665
  * `params`: Define parameters directly from an `Entity`
672
- * `success`: (former entity) The `Entity` to be used to present by default this route
673
- * `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities
666
+ * `success`: (former entity) The `Entity` to be used to present the success response for this route.
667
+ * `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities.
668
+ * `default`: The definition and `Entity` used to present the default response for this route.
674
669
  * `named`: A helper to give a route a name and find it with this name in the documentation Hash
675
670
  * `headers`: A definition of the used Headers
676
671
  * Other options can be found in [grape-swagger][grape-swagger]
@@ -800,6 +795,7 @@ Grape allows you to access only the parameters that have been declared by your `
800
795
 
801
796
  * Filter out the params that have been passed, but are not allowed.
802
797
  * Include any optional params that are declared but not passed.
798
+ * Perform any parameter renaming on the resulting hash.
803
799
 
804
800
  Consider the following API endpoint:
805
801
 
@@ -994,8 +990,10 @@ curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d
994
990
  ````json
995
991
  {
996
992
  "declared_params": {
997
- "first_name": "first name",
998
- "last_name": null
993
+ "user": {
994
+ "first_name": "first name",
995
+ "last_name": null
996
+ }
999
997
  }
1000
998
  }
1001
999
  ````
@@ -1082,6 +1080,102 @@ curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d
1082
1080
  }
1083
1081
  ````
1084
1082
 
1083
+ ### Evaluate Given
1084
+
1085
+ By default `declared(params)` will not evaluate `given` and return all parameters. Use `evaluate_given` to evaluate all `given` blocks and return only parameters that satisfy `given` conditions. Consider the following API:
1086
+
1087
+ ````ruby
1088
+ format :json
1089
+
1090
+ params do
1091
+ optional :child_id, type: Integer
1092
+ given :child_id do
1093
+ requires :father_id, type: Integer
1094
+ end
1095
+ end
1096
+
1097
+ post 'child' do
1098
+ { 'declared_params' => declared(params, evaluate_given: true) }
1099
+ end
1100
+ ````
1101
+
1102
+ **Request**
1103
+
1104
+ ````bash
1105
+ curl -X POST -H "Content-Type: application/json" localhost:9292/child -d '{"father_id": 1}'
1106
+ ````
1107
+
1108
+ **Response with evaluate_given:false**
1109
+
1110
+ ````json
1111
+ {
1112
+ "declared_params": {
1113
+ "child_id": null,
1114
+ "father_id": 1
1115
+ }
1116
+ }
1117
+ ````
1118
+
1119
+ **Response with evaluate_given:true**
1120
+
1121
+ ````json
1122
+ {
1123
+ "declared_params": {
1124
+ "child_id": null
1125
+ }
1126
+ }
1127
+ ````
1128
+
1129
+ It also works on nested hashes:
1130
+
1131
+ ````ruby
1132
+ format :json
1133
+
1134
+ params do
1135
+ requires :child, type: Hash do
1136
+ optional :child_id, type: Integer
1137
+ given :child_id do
1138
+ requires :father_id, type: Integer
1139
+ end
1140
+ end
1141
+ end
1142
+
1143
+ post 'child' do
1144
+ { 'declared_params' => declared(params, evaluate_given: true) }
1145
+ end
1146
+ ````
1147
+
1148
+ **Request**
1149
+
1150
+ ````bash
1151
+ curl -X POST -H "Content-Type: application/json" localhost:9292/child -d '{"child": {"father_id": 1}}'
1152
+ ````
1153
+
1154
+ **Response with evaluate_given:false**
1155
+
1156
+ ````json
1157
+ {
1158
+ "declared_params": {
1159
+ "child": {
1160
+ "child_id": null,
1161
+ "father_id": 1
1162
+ }
1163
+ }
1164
+ }
1165
+ ````
1166
+
1167
+ **Response with evaluate_given:true**
1168
+
1169
+ ````json
1170
+ {
1171
+ "declared_params": {
1172
+ "child": {
1173
+ "child_id": null
1174
+ }
1175
+ }
1176
+ }
1177
+ ````
1178
+
1085
1179
  ## Parameter Validation and Coercion
1086
1180
 
1087
1181
  You can define validations and coercion options for your parameters using a `params` block.
@@ -1450,7 +1544,7 @@ resource :users do
1450
1544
  end
1451
1545
  ```
1452
1546
 
1453
- The value passed to `as` will be the key when calling `params` or `declared(params)`.
1547
+ The value passed to `as` will be the key when calling `declared(params)`.
1454
1548
 
1455
1549
  ### Built-in Validators
1456
1550
 
@@ -1494,6 +1588,15 @@ params do
1494
1588
  end
1495
1589
  ```
1496
1590
 
1591
+ Note endless ranges are also supported with ActiveSupport >= 6.0, but they require that the type be provided.
1592
+
1593
+ ```ruby
1594
+ params do
1595
+ requires :minimum, type: Integer, values: 10..
1596
+ optional :maximum, type: Integer, values: ..10
1597
+ end
1598
+ ```
1599
+
1497
1600
  Note that *both* range endpoints have to be a `#kind_of?` your `:type` option (if you don't supply the `:type` option, it will be guessed to be equal to the class of the range's first endpoint). So the following is invalid:
1498
1601
 
1499
1602
  ```ruby
@@ -1529,6 +1632,14 @@ end
1529
1632
 
1530
1633
  While Procs are convenient for single cases, consider using [Custom Validators](#custom-validators) in cases where a validation is used more than once.
1531
1634
 
1635
+ 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`.
1636
+
1637
+ ```ruby
1638
+ params do
1639
+ requires :state, type: Symbol, values: [:active, :inactive]
1640
+ end
1641
+ ```
1642
+
1532
1643
  #### `except_values`
1533
1644
 
1534
1645
  Parameters can be restricted from having a specific set of values with the `:except_values` option.
@@ -1731,10 +1842,10 @@ end
1731
1842
  ### Custom Validators
1732
1843
 
1733
1844
  ```ruby
1734
- class AlphaNumeric < Grape::Validations::Base
1845
+ class AlphaNumeric < Grape::Validations::Validators::Base
1735
1846
  def validate_param!(attr_name, params)
1736
1847
  unless params[attr_name] =~ /\A[[:alnum:]]+\z/
1737
- fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: 'must consist of alpha-numeric characters'
1848
+ raise Grape::Exceptions::Validation.new params: [@scope.full_name(attr_name)], message: 'must consist of alpha-numeric characters'
1738
1849
  end
1739
1850
  end
1740
1851
  end
@@ -1749,10 +1860,10 @@ end
1749
1860
  You can also create custom classes that take parameters.
1750
1861
 
1751
1862
  ```ruby
1752
- class Length < Grape::Validations::Base
1863
+ class Length < Grape::Validations::Validators::Base
1753
1864
  def validate_param!(attr_name, params)
1754
1865
  unless params[attr_name].length <= @option
1755
- fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long"
1866
+ raise Grape::Exceptions::Validation.new params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long"
1756
1867
  end
1757
1868
  end
1758
1869
  end
@@ -1767,7 +1878,7 @@ end
1767
1878
  You can also create custom validation that use request to validate the attribute. For example if you want to have parameters that are available to only admins, you can do the following.
1768
1879
 
1769
1880
  ```ruby
1770
- class Admin < Grape::Validations::Base
1881
+ class Admin < Grape::Validations::Validators::Base
1771
1882
  def validate(request)
1772
1883
  # return if the param we are checking was not in request
1773
1884
  # @attrs is a list containing the attribute we are currently validating
@@ -1778,7 +1889,7 @@ class Admin < Grape::Validations::Base
1778
1889
  return unless @option
1779
1890
  # check if user is admin or not
1780
1891
  # as an example get a token from request and check if it's admin or not
1781
- fail Grape::Exceptions::Validation, params: @attrs, message: 'Can not set admin-only field.' unless request.headers['X-Access-Token'] == 'admin'
1892
+ raise Grape::Exceptions::Validation.new params: @attrs, message: 'Can not set admin-only field.' unless request.headers['X-Access-Token'] == 'admin'
1782
1893
  end
1783
1894
  end
1784
1895
  ```
@@ -2237,6 +2348,18 @@ params do
2237
2348
  end
2238
2349
  ```
2239
2350
 
2351
+ If documentation isn't needed (for instance, it is an internal API), documentation can be disabled.
2352
+
2353
+ ```ruby
2354
+ class API < Grape::API
2355
+ do_not_document!
2356
+
2357
+ # endpoints...
2358
+ end
2359
+ ```
2360
+
2361
+ In this case, Grape won't create objects related to documentation which are retained in RAM forever.
2362
+
2240
2363
  ## Cookies
2241
2364
 
2242
2365
  You can set, get and delete your cookies very simply using `cookies` method.
@@ -3228,6 +3351,17 @@ end
3228
3351
 
3229
3352
  Use `body false` to return `204 No Content` without any data or content-type.
3230
3353
 
3354
+ If you want to empty the body with an HTTP status code other than `204 No Content`, you can override the status code after specifying `body false` as follows
3355
+
3356
+ ```ruby
3357
+ class API < Grape::API
3358
+ get '/' do
3359
+ body false
3360
+ status 304
3361
+ end
3362
+ end
3363
+ ```
3364
+
3231
3365
  You can also set the response to a file with `sendfile`. This works with the
3232
3366
  [Rack::Sendfile](https://www.rubydoc.info/gems/rack/Rack/Sendfile) middleware to optimally send
3233
3367
  the file through your web server software.
@@ -3285,12 +3419,20 @@ http_basic do |username, password|
3285
3419
  end
3286
3420
  ```
3287
3421
 
3422
+ Digest auth supports clear-text passwords and password hashes.
3423
+
3288
3424
  ```ruby
3289
3425
  http_digest({ realm: 'Test Api', opaque: 'app secret' }) do |username|
3290
3426
  # lookup the user's password here
3291
3427
  end
3292
3428
  ```
3293
3429
 
3430
+ ```ruby
3431
+ http_digest(realm: { realm: 'Test Api', opaque: 'app secret', passwords_hashed: true }) do |username|
3432
+ # lookup the user's password hash here
3433
+ end
3434
+ ```
3435
+
3294
3436
  ### Register custom middleware for authentication
3295
3437
 
3296
3438
  Grape can use custom Middleware for authentication. How to implement these
@@ -3641,6 +3783,14 @@ You can access the controller params, headers, and helpers through the context w
3641
3783
  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.
3642
3784
  You only have to implement the helpers to access the specific `env` variable.
3643
3785
 
3786
+ 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.
3787
+
3788
+ ```ruby
3789
+ class Company::Application < Rails::Application
3790
+ config.middleware.insert_before(Rack::Attack, Middleware::ApiLogger)
3791
+ end
3792
+ ```
3793
+
3644
3794
  ### Remote IP
3645
3795
 
3646
3796
  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`.
@@ -3674,7 +3824,7 @@ Use `rack-test` and define your API as `app`.
3674
3824
  You can test a Grape API with RSpec by making HTTP requests and examining the response.
3675
3825
 
3676
3826
  ```ruby
3677
- require 'spec_helper'
3827
+
3678
3828
 
3679
3829
  describe Twitter::API do
3680
3830
  include Rack::Test::Methods
@@ -3945,6 +4095,7 @@ Grape integrates with following third-party tools:
3945
4095
  * **[Skylight](https://www.skylight.io/)** - [skylight](https://github.com/skylightio/skylight-ruby) gem, [documentation](https://docs.skylight.io/grape/)
3946
4096
  * **[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)
3947
4097
  * **[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)
4098
+ * **[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)
3948
4099
 
3949
4100
  ## Contributing to Grape
3950
4101
 
data/UPGRADING.md CHANGED
@@ -1,13 +1,68 @@
1
1
  Upgrading Grape
2
2
  ===============
3
3
 
4
+ ### Upgrading to >= 1.7.0
5
+
6
+ #### Exceptions renaming
7
+
8
+ The following exceptions has been renamed for consistency through exceptions naming :
9
+
10
+ * `MissingGroupTypeError` => `MissingGroupType`
11
+ * `UnsupportedGroupTypeError` => `UnsupportedGroupType`
12
+
13
+ See [#2227](https://github.com/ruby-grape/grape/pull/2227) for more information.
14
+
15
+ #### Handling Multipart Limit Errors
16
+
17
+ Rack supports a configurable limit on the number of files created from multipart parameters (`Rack::Utils.multipart_part_limit`) and raises an error if params are received that create too many files. If you were handling the Rack error directly, Grape now wraps that error in `Grape::Execeptions::TooManyMultipartFiles`. Additionally, Grape will return a 413 status code if the exception goes unhandled.
18
+
19
+ ### Upgrading to >= 1.6.0
20
+
21
+ #### Parameter renaming with :as
22
+
23
+ Prior to 1.6.0 the [parameter renaming](https://github.com/ruby-grape/grape#renaming) with `:as` was directly touching the request payload ([`#params`](https://github.com/ruby-grape/grape#parameters)) while duplicating the old and the new key to be both available in the hash. This allowed clients to bypass any validation in case they knew the internal name of the parameter. Unfortunately, in combination with [grape-swagger](https://github.com/ruby-grape/grape-swagger) the internal name (name set with `:as`) of the parameters were documented.
24
+
25
+ This behavior was fixed. Parameter renaming is now done when using the [`#declared(params)`](https://github.com/ruby-grape/grape#declared) parameters helper. This stops confusing validation/coercion behavior.
26
+
27
+ Here comes an illustration of the old and new behaviour as code:
28
+
29
+ ```ruby
30
+ # (1) Rename a to b, while client sends +a+
31
+ optional :a, type: Integer, as: :b
32
+ params = { a: 1 }
33
+ declared(params, include_missing: false)
34
+ # expected => { b: 1 }
35
+ # actual => { b: 1 }
36
+
37
+ # (2) Rename a to b, while client sends +b+
38
+ optional :a, type: Integer, as: :b, values: [1, 2, 3]
39
+ params = { b: '5' }
40
+ declared(params, include_missing: false)
41
+ # expected => { } (>= 1.6.0)
42
+ # actual => { b: '5' } (uncasted, unvalidated, <= 1.5.3)
43
+ ```
44
+
45
+ Another implication of this change is the dependent parameter resolution. Prior to 1.6.0 the following code produced a `Grape::Exceptions::UnknownParameter` because `:a` was replaced by `:b`:
46
+
47
+ ```ruby
48
+ params do
49
+ optional :a, as: :b
50
+ given :a do # (<= 1.5.3 you had to reference +:b+ here to make it work)
51
+ requires :c
52
+ end
53
+ end
54
+ ```
55
+
56
+ This code now works without any errors, as the renaming is just an internal behaviour of the `#declared(params)` parameter helper.
57
+
58
+ See [#2189](https://github.com/ruby-grape/grape/pull/2189) for more information.
4
59
 
5
60
  ### Upgrading to >= 1.5.3
6
61
 
7
- ### Nil value and coercion
62
+ #### Nil value and coercion
8
63
 
9
64
  Prior to 1.2.5 version passing a `nil` value for a parameter with a custom coercer would invoke the coercer, and not passing a parameter would not invoke it.
10
- This behavior was not tested or documented. Version 1.3.0 quietly changed this behavior, in such that `nil` values skipped the coercion. Version 1.5.3 fixes and documents this as follows:
65
+ This behavior was not tested or documented. Version 1.3.0 quietly changed this behavior, in that `nil` values skipped the coercion. Version 1.5.3 fixes and documents this as follows:
11
66
 
12
67
  ```ruby
13
68
  class Api < Grape::API
@@ -157,13 +212,13 @@ end
157
212
 
158
213
  #### Nil values for structures
159
214
 
160
- Nil values always been a special case when dealing with types especially with the following structures:
215
+ Nil values have always been a special case when dealing with types, especially with the following structures:
161
216
 
162
217
  - Array
163
218
  - Hash
164
219
  - Set
165
220
 
166
- The behavior for these structures has change through out the latest releases. For example:
221
+ The behavior for these structures has changed throughout the latest releases. For example:
167
222
 
168
223
  ```ruby
169
224
  class Api < Grape::API
@@ -216,6 +271,8 @@ end
216
271
 
217
272
  ### Upgrading to >= 1.3.0
218
273
 
274
+ You will need to upgrade to this version if you depend on `rack >= 2.1.0`.
275
+
219
276
  #### Ruby
220
277
 
221
278
  After adding dry-types, Ruby 2.4 or newer is required.
data/grape.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
4
  require 'grape/version'
5
5
 
6
6
  Gem::Specification.new do |s|
@@ -14,17 +14,17 @@ Gem::Specification.new do |s|
14
14
  s.description = 'A Ruby framework for rapid API development with great conventions.'
15
15
  s.license = 'MIT'
16
16
  s.metadata = {
17
- 'bug_tracker_uri' => 'https://github.com/ruby-grape/grape/issues',
18
- 'changelog_uri' => "https://github.com/ruby-grape/grape/blob/v#{s.version}/CHANGELOG.md",
17
+ 'bug_tracker_uri' => 'https://github.com/ruby-grape/grape/issues',
18
+ 'changelog_uri' => "https://github.com/ruby-grape/grape/blob/v#{s.version}/CHANGELOG.md",
19
19
  'documentation_uri' => "https://www.rubydoc.info/gems/grape/#{s.version}",
20
- 'source_code_uri' => "https://github.com/ruby-grape/grape/tree/v#{s.version}"
20
+ 'source_code_uri' => "https://github.com/ruby-grape/grape/tree/v#{s.version}"
21
21
  }
22
22
 
23
23
  s.add_runtime_dependency 'activesupport'
24
24
  s.add_runtime_dependency 'builder'
25
25
  s.add_runtime_dependency 'dry-types', '>= 1.1'
26
26
  s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0'
27
- s.add_runtime_dependency 'rack', '>= 1.3.0'
27
+ s.add_runtime_dependency 'rack', '>= 1.3.0', '< 3'
28
28
  s.add_runtime_dependency 'rack-accept'
29
29
 
30
30
  s.files = %w[CHANGELOG.md CONTRIBUTING.md README.md grape.png UPGRADING.md LICENSE]
@@ -32,5 +32,5 @@ Gem::Specification.new do |s|
32
32
  s.files += Dir['lib/**/*']
33
33
  s.test_files = Dir['spec/**/*']
34
34
  s.require_paths = ['lib']
35
- s.required_ruby_version = '>= 2.4.0'
35
+ s.required_ruby_version = '>= 2.6.0'
36
36
  end