grape 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (253) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +5 -3
  4. data/UPGRADING.md +43 -0
  5. data/grape.gemspec +10 -1
  6. data/lib/grape.rb +2 -2
  7. data/lib/grape/api.rb +2 -0
  8. data/lib/grape/api/helpers.rb +2 -0
  9. data/lib/grape/api/instance.rb +4 -2
  10. data/lib/grape/config.rb +2 -0
  11. data/lib/grape/cookies.rb +2 -0
  12. data/lib/grape/dsl/api.rb +2 -0
  13. data/lib/grape/dsl/callbacks.rb +2 -0
  14. data/lib/grape/dsl/configuration.rb +2 -0
  15. data/lib/grape/dsl/desc.rb +2 -0
  16. data/lib/grape/dsl/headers.rb +2 -0
  17. data/lib/grape/dsl/helpers.rb +3 -1
  18. data/lib/grape/dsl/inside_route.rb +7 -4
  19. data/lib/grape/dsl/logger.rb +2 -0
  20. data/lib/grape/dsl/middleware.rb +2 -0
  21. data/lib/grape/dsl/parameters.rb +4 -2
  22. data/lib/grape/dsl/request_response.rb +4 -2
  23. data/lib/grape/dsl/routing.rb +3 -1
  24. data/lib/grape/dsl/settings.rb +7 -1
  25. data/lib/grape/dsl/validations.rb +2 -0
  26. data/lib/grape/eager_load.rb +2 -0
  27. data/lib/grape/endpoint.rb +13 -7
  28. data/lib/grape/error_formatter.rb +3 -1
  29. data/lib/grape/error_formatter/base.rb +2 -0
  30. data/lib/grape/error_formatter/json.rb +2 -0
  31. data/lib/grape/error_formatter/txt.rb +2 -0
  32. data/lib/grape/error_formatter/xml.rb +2 -0
  33. data/lib/grape/exceptions/base.rb +11 -9
  34. data/lib/grape/exceptions/incompatible_option_values.rb +2 -0
  35. data/lib/grape/exceptions/invalid_accept_header.rb +2 -0
  36. data/lib/grape/exceptions/invalid_formatter.rb +2 -0
  37. data/lib/grape/exceptions/invalid_message_body.rb +2 -0
  38. data/lib/grape/exceptions/invalid_response.rb +2 -0
  39. data/lib/grape/exceptions/invalid_version_header.rb +2 -0
  40. data/lib/grape/exceptions/invalid_versioner_option.rb +2 -0
  41. data/lib/grape/exceptions/invalid_with_option_for_represent.rb +2 -0
  42. data/lib/grape/exceptions/method_not_allowed.rb +2 -0
  43. data/lib/grape/exceptions/missing_group_type.rb +2 -0
  44. data/lib/grape/exceptions/missing_mime_type.rb +2 -0
  45. data/lib/grape/exceptions/missing_option.rb +2 -0
  46. data/lib/grape/exceptions/missing_vendor_option.rb +2 -0
  47. data/lib/grape/exceptions/unknown_options.rb +2 -0
  48. data/lib/grape/exceptions/unknown_parameter.rb +2 -0
  49. data/lib/grape/exceptions/unknown_validator.rb +2 -0
  50. data/lib/grape/exceptions/unsupported_group_type.rb +2 -0
  51. data/lib/grape/exceptions/validation.rb +3 -1
  52. data/lib/grape/exceptions/validation_array_errors.rb +2 -0
  53. data/lib/grape/exceptions/validation_errors.rb +2 -0
  54. data/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +4 -3
  55. data/lib/grape/extensions/deep_mergeable_hash.rb +2 -0
  56. data/lib/grape/extensions/deep_symbolize_hash.rb +2 -0
  57. data/lib/grape/extensions/hash.rb +2 -0
  58. data/lib/grape/extensions/hashie/mash.rb +2 -0
  59. data/lib/grape/formatter.rb +5 -3
  60. data/lib/grape/formatter/json.rb +2 -0
  61. data/lib/grape/formatter/serializable_hash.rb +2 -0
  62. data/lib/grape/formatter/txt.rb +2 -0
  63. data/lib/grape/formatter/xml.rb +2 -0
  64. data/lib/grape/http/headers.rb +23 -17
  65. data/lib/grape/middleware/auth/base.rb +2 -0
  66. data/lib/grape/middleware/auth/dsl.rb +2 -0
  67. data/lib/grape/middleware/auth/strategies.rb +2 -0
  68. data/lib/grape/middleware/auth/strategy_info.rb +2 -0
  69. data/lib/grape/middleware/base.rb +4 -2
  70. data/lib/grape/middleware/error.rb +3 -1
  71. data/lib/grape/middleware/filter.rb +2 -0
  72. data/lib/grape/middleware/formatter.rb +5 -3
  73. data/lib/grape/middleware/globals.rb +2 -0
  74. data/lib/grape/middleware/helpers.rb +2 -0
  75. data/lib/grape/middleware/stack.rb +2 -0
  76. data/lib/grape/middleware/versioner.rb +2 -0
  77. data/lib/grape/middleware/versioner/accept_version_header.rb +2 -0
  78. data/lib/grape/middleware/versioner/header.rb +2 -0
  79. data/lib/grape/middleware/versioner/param.rb +3 -1
  80. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -0
  81. data/lib/grape/middleware/versioner/path.rb +2 -0
  82. data/lib/grape/namespace.rb +2 -0
  83. data/lib/grape/parser.rb +3 -1
  84. data/lib/grape/parser/json.rb +2 -0
  85. data/lib/grape/parser/xml.rb +2 -0
  86. data/lib/grape/path.rb +2 -0
  87. data/lib/grape/presenters/presenter.rb +2 -0
  88. data/lib/grape/request.rb +3 -1
  89. data/lib/grape/router.rb +11 -6
  90. data/lib/grape/router/attribute_translator.rb +18 -8
  91. data/lib/grape/router/pattern.rb +6 -3
  92. data/lib/grape/router/route.rb +7 -2
  93. data/lib/grape/serve_file/file_body.rb +2 -0
  94. data/lib/grape/serve_file/file_response.rb +2 -0
  95. data/lib/grape/serve_file/sendfile_response.rb +2 -0
  96. data/lib/grape/util/base_inheritable.rb +2 -0
  97. data/lib/grape/util/content_types.rb +2 -0
  98. data/lib/grape/util/endpoint_configuration.rb +2 -0
  99. data/lib/grape/util/env.rb +19 -17
  100. data/lib/grape/util/inheritable_setting.rb +2 -0
  101. data/lib/grape/util/inheritable_values.rb +2 -0
  102. data/lib/grape/util/json.rb +2 -0
  103. data/lib/grape/util/lazy_block.rb +2 -0
  104. data/lib/grape/util/lazy_value.rb +2 -0
  105. data/lib/grape/util/registrable.rb +2 -0
  106. data/lib/grape/util/reverse_stackable_values.rb +2 -0
  107. data/lib/grape/util/stackable_values.rb +3 -0
  108. data/lib/grape/util/strict_hash_configuration.rb +2 -0
  109. data/lib/grape/util/xml.rb +2 -0
  110. data/lib/grape/validations.rb +2 -0
  111. data/lib/grape/validations/attributes_iterator.rb +3 -3
  112. data/lib/grape/validations/multiple_attributes_iterator.rb +2 -0
  113. data/lib/grape/validations/params_scope.rb +23 -10
  114. data/lib/grape/validations/single_attribute_iterator.rb +13 -2
  115. data/lib/grape/validations/types.rb +7 -30
  116. data/lib/grape/validations/types/array_coercer.rb +56 -0
  117. data/lib/grape/validations/types/build_coercer.rb +49 -48
  118. data/lib/grape/validations/types/custom_type_coercer.rb +15 -49
  119. data/lib/grape/validations/types/custom_type_collection_coercer.rb +10 -25
  120. data/lib/grape/validations/types/dry_type_coercer.rb +41 -0
  121. data/lib/grape/validations/types/file.rb +10 -9
  122. data/lib/grape/validations/types/json.rb +11 -8
  123. data/lib/grape/validations/types/multiple_type_coercer.rb +14 -33
  124. data/lib/grape/validations/types/primitive_coercer.rb +58 -0
  125. data/lib/grape/validations/types/set_coercer.rb +38 -0
  126. data/lib/grape/validations/types/variant_collection_coercer.rb +4 -12
  127. data/lib/grape/validations/validator_factory.rb +2 -0
  128. data/lib/grape/validations/validators/all_or_none.rb +3 -1
  129. data/lib/grape/validations/validators/allow_blank.rb +3 -1
  130. data/lib/grape/validations/validators/as.rb +2 -0
  131. data/lib/grape/validations/validators/at_least_one_of.rb +3 -1
  132. data/lib/grape/validations/validators/base.rb +8 -5
  133. data/lib/grape/validations/validators/coerce.rb +43 -26
  134. data/lib/grape/validations/validators/default.rb +2 -0
  135. data/lib/grape/validations/validators/exactly_one_of.rb +3 -1
  136. data/lib/grape/validations/validators/except_values.rb +3 -1
  137. data/lib/grape/validations/validators/multiple_params_base.rb +2 -0
  138. data/lib/grape/validations/validators/mutual_exclusion.rb +3 -1
  139. data/lib/grape/validations/validators/presence.rb +3 -1
  140. data/lib/grape/validations/validators/regexp.rb +3 -1
  141. data/lib/grape/validations/validators/same_as.rb +6 -3
  142. data/lib/grape/validations/validators/values.rb +17 -5
  143. data/lib/grape/version.rb +3 -1
  144. data/spec/grape/api/custom_validations_spec.rb +5 -3
  145. data/spec/grape/api/deeply_included_options_spec.rb +2 -0
  146. data/spec/grape/api/defines_boolean_in_params_spec.rb +5 -3
  147. data/spec/grape/api/inherited_helpers_spec.rb +2 -0
  148. data/spec/grape/api/instance_spec.rb +54 -0
  149. data/spec/grape/api/invalid_format_spec.rb +2 -0
  150. data/spec/grape/api/namespace_parameters_in_route_spec.rb +2 -0
  151. data/spec/grape/api/nested_helpers_spec.rb +2 -0
  152. data/spec/grape/api/optional_parameters_in_route_spec.rb +2 -0
  153. data/spec/grape/api/parameters_modification_spec.rb +3 -1
  154. data/spec/grape/api/patch_method_helpers_spec.rb +2 -0
  155. data/spec/grape/api/recognize_path_spec.rb +2 -0
  156. data/spec/grape/api/required_parameters_in_route_spec.rb +2 -0
  157. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +2 -0
  158. data/spec/grape/api/routes_with_requirements_spec.rb +2 -0
  159. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +2 -0
  160. data/spec/grape/api/shared_helpers_spec.rb +2 -0
  161. data/spec/grape/api_remount_spec.rb +2 -0
  162. data/spec/grape/api_spec.rb +27 -5
  163. data/spec/grape/config_spec.rb +2 -0
  164. data/spec/grape/dsl/callbacks_spec.rb +2 -0
  165. data/spec/grape/dsl/configuration_spec.rb +2 -0
  166. data/spec/grape/dsl/desc_spec.rb +2 -0
  167. data/spec/grape/dsl/headers_spec.rb +2 -0
  168. data/spec/grape/dsl/helpers_spec.rb +4 -2
  169. data/spec/grape/dsl/inside_route_spec.rb +2 -0
  170. data/spec/grape/dsl/logger_spec.rb +2 -0
  171. data/spec/grape/dsl/middleware_spec.rb +2 -0
  172. data/spec/grape/dsl/parameters_spec.rb +2 -0
  173. data/spec/grape/dsl/request_response_spec.rb +2 -0
  174. data/spec/grape/dsl/routing_spec.rb +2 -0
  175. data/spec/grape/dsl/settings_spec.rb +2 -0
  176. data/spec/grape/dsl/validations_spec.rb +2 -0
  177. data/spec/grape/endpoint_spec.rb +3 -1
  178. data/spec/grape/entity_spec.rb +2 -0
  179. data/spec/grape/exceptions/base_spec.rb +3 -1
  180. data/spec/grape/exceptions/body_parse_errors_spec.rb +2 -0
  181. data/spec/grape/exceptions/invalid_accept_header_spec.rb +2 -0
  182. data/spec/grape/exceptions/invalid_formatter_spec.rb +2 -0
  183. data/spec/grape/exceptions/invalid_response_spec.rb +2 -0
  184. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +2 -0
  185. data/spec/grape/exceptions/missing_mime_type_spec.rb +2 -0
  186. data/spec/grape/exceptions/missing_option_spec.rb +2 -0
  187. data/spec/grape/exceptions/unknown_options_spec.rb +2 -0
  188. data/spec/grape/exceptions/unknown_validator_spec.rb +2 -0
  189. data/spec/grape/exceptions/validation_errors_spec.rb +2 -0
  190. data/spec/grape/exceptions/validation_spec.rb +3 -1
  191. data/spec/grape/extensions/param_builders/hash_spec.rb +2 -0
  192. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +2 -0
  193. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +2 -0
  194. data/spec/grape/integration/global_namespace_function_spec.rb +2 -0
  195. data/spec/grape/integration/rack_sendfile_spec.rb +2 -0
  196. data/spec/grape/integration/rack_spec.rb +3 -1
  197. data/spec/grape/loading_spec.rb +2 -0
  198. data/spec/grape/middleware/auth/base_spec.rb +2 -0
  199. data/spec/grape/middleware/auth/dsl_spec.rb +2 -0
  200. data/spec/grape/middleware/auth/strategies_spec.rb +2 -0
  201. data/spec/grape/middleware/base_spec.rb +2 -0
  202. data/spec/grape/middleware/error_spec.rb +2 -0
  203. data/spec/grape/middleware/exception_spec.rb +3 -1
  204. data/spec/grape/middleware/formatter_spec.rb +17 -10
  205. data/spec/grape/middleware/globals_spec.rb +2 -0
  206. data/spec/grape/middleware/stack_spec.rb +2 -0
  207. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +3 -1
  208. data/spec/grape/middleware/versioner/header_spec.rb +3 -1
  209. data/spec/grape/middleware/versioner/param_spec.rb +3 -1
  210. data/spec/grape/middleware/versioner/path_spec.rb +3 -1
  211. data/spec/grape/middleware/versioner_spec.rb +2 -0
  212. data/spec/grape/named_api_spec.rb +2 -0
  213. data/spec/grape/parser_spec.rb +7 -5
  214. data/spec/grape/path_spec.rb +2 -0
  215. data/spec/grape/presenters/presenter_spec.rb +2 -0
  216. data/spec/grape/request_spec.rb +2 -0
  217. data/spec/grape/util/inheritable_setting_spec.rb +2 -0
  218. data/spec/grape/util/inheritable_values_spec.rb +2 -0
  219. data/spec/grape/util/reverse_stackable_values_spec.rb +2 -0
  220. data/spec/grape/util/stackable_values_spec.rb +3 -1
  221. data/spec/grape/util/strict_hash_configuration_spec.rb +2 -0
  222. data/spec/grape/validations/attributes_iterator_spec.rb +2 -0
  223. data/spec/grape/validations/instance_behaivour_spec.rb +4 -2
  224. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +2 -0
  225. data/spec/grape/validations/params_scope_spec.rb +3 -1
  226. data/spec/grape/validations/single_attribute_iterator_spec.rb +18 -4
  227. data/spec/grape/validations/types_spec.rb +8 -35
  228. data/spec/grape/validations/validators/all_or_none_spec.rb +2 -0
  229. data/spec/grape/validations/validators/allow_blank_spec.rb +2 -0
  230. data/spec/grape/validations/validators/at_least_one_of_spec.rb +2 -0
  231. data/spec/grape/validations/validators/coerce_spec.rb +43 -66
  232. data/spec/grape/validations/validators/default_spec.rb +2 -0
  233. data/spec/grape/validations/validators/exactly_one_of_spec.rb +2 -0
  234. data/spec/grape/validations/validators/except_values_spec.rb +3 -1
  235. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +2 -0
  236. data/spec/grape/validations/validators/presence_spec.rb +30 -0
  237. data/spec/grape/validations/validators/regexp_spec.rb +2 -0
  238. data/spec/grape/validations/validators/same_as_spec.rb +2 -0
  239. data/spec/grape/validations/validators/values_spec.rb +29 -4
  240. data/spec/grape/validations_spec.rb +61 -3
  241. data/spec/integration/multi_json/json_spec.rb +2 -0
  242. data/spec/integration/multi_xml/xml_spec.rb +2 -0
  243. data/spec/shared/versioning_examples.rb +2 -0
  244. data/spec/spec_helper.rb +15 -0
  245. data/spec/support/basic_auth_encode_helpers.rb +2 -0
  246. data/spec/support/content_type_helpers.rb +2 -0
  247. data/spec/support/endpoint_faker.rb +2 -0
  248. data/spec/support/file_streamer.rb +2 -0
  249. data/spec/support/integer_helpers.rb +2 -0
  250. data/spec/support/versioned_helpers.rb +4 -2
  251. metadata +119 -111
  252. data/lib/grape/extensions/deep_hash_with_indifferent_access.rb +0 -18
  253. 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: 8934b2070d7c44a7100315712c05ee9e76eff602290b30f475f6e2e324c5392c
4
- data.tar.gz: 0d618a852be97bf103c7f783702342b030440834fedd725b4e6a90e03a8b0556
3
+ metadata.gz: 826e1365751c85c3f1f7d433e842a76c8a7f5dc6c4a1b13128679e4d56b2ccf5
4
+ data.tar.gz: af8aef528c40764a53a3e397c306835745943a1d376ab3738bf7aa2547ef75d1
5
5
  SHA512:
6
- metadata.gz: f11c651eb7dea86dd45065c04cdebcbb2635cf8136536850b245d4ad94eac921a4218f191cc5f523968cdc4708ee7ede49fce17de21b97b96edcd82426c06795
7
- data.tar.gz: 8266b0bf359c1ed96b7aacd9bbecacfe6ef5f406b94d54a1a9c6dfdbf18d95967f8c853f13dfab642631e261f81893bcc5323e83c0d27a04226bdc03d7b19381
6
+ metadata.gz: 0af9a855214f1fbacd92403111aa1f4761b7257adf6ca9dbd6ab4e1cb889469b76a489971d058a58e98d3bf6906dacb67eb8a5eae11aad16782f318b3453988b
7
+ data.tar.gz: 25004acd2431ab7cd174466e82ca5240b888ca045036227909ed9c8c886cd8706f1d3b696f4b1ede8eaa69c68c156fe064557afea8cdf53c9d39b136db7ae4b1
@@ -1,3 +1,26 @@
1
+ ### 1.3.0 (2020/01/11)
2
+
3
+ #### Features
4
+
5
+ * [#1949](https://github.com/ruby-grape/grape/pull/1949): Add support for Ruby 2.7 - [@nbulaj](https://github.com/nbulaj).
6
+ * [#1948](https://github.com/ruby-grape/grape/pull/1948): Relax `dry-types` dependency version - [@nbulaj](https://github.com/nbulaj).
7
+ * [#1944](https://github.com/ruby-grape/grape/pull/1944): Reduces `attribute_translator` string allocations - [@ericproulx](https://github.com/ericproulx).
8
+ * [#1943](https://github.com/ruby-grape/grape/pull/1943): Reduces number of regex string allocations - [@ericproulx](https://github.com/ericproulx).
9
+ * [#1942](https://github.com/ruby-grape/grape/pull/1942): Optimizes retained memory methods - [@ericproulx](https://github.com/ericproulx).
10
+ * [#1941](https://github.com/ruby-grape/grape/pull/1941): Adds frozen string literal - [@ericproulx](https://github.com/ericproulx).
11
+ * [#1940](https://github.com/ruby-grape/grape/pull/1940): Gets rid of a needless step in `HashWithIndifferentAccess` - [@dnesteryuk](https://github.com/dnesteryuk).
12
+ * [#1938](https://github.com/ruby-grape/grape/pull/1938): Adds project metadata to the gemspec - [@orien](https://github.com/orien).
13
+ * [#1920](https://github.com/ruby-grape/grape/pull/1920): Replaces Virtus with dry-types - [@dnesteryuk](https://github.com/dnesteryuk).
14
+ * [#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).
15
+
16
+ #### Fixes
17
+
18
+ * [#1965](https://github.com/ruby-grape/grape/pull/1965): Fix typos in README - [@davidalee](https://github.com/davidalee).
19
+ * [#1963](https://github.com/ruby-grape/grape/pull/1963): The values validator must properly work with booleans - [@dnesteryuk](https://github.com/dnesteryuk).
20
+ * [#1950](https://github.com/ruby-grape/grape/pull/1950): Consider the allow_blank option in the values validator - [@dnesteryuk](https://github.com/dnesteryuk).
21
+ * [#1947](https://github.com/ruby-grape/grape/pull/1947): Careful check for empty params - [@dnesteryuk](https://github.com/dnesteryuk).
22
+ * [#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).
23
+
1
24
  ### 1.2.5 (2019/12/01)
2
25
 
3
26
  #### Features
data/README.md CHANGED
@@ -154,7 +154,7 @@ content negotiation, versioning and much more.
154
154
 
155
155
  ## Stable Release
156
156
 
157
- You're reading the documentation for the stable release of Grape, **1.2.5**.
157
+ You're reading the documentation for the stable release of Grape, **1.3.0**.
158
158
  Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
159
159
 
160
160
  ## Project Resources
@@ -166,6 +166,8 @@ Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
166
166
 
167
167
  ## Installation
168
168
 
169
+ Ruby 2.4 or newer is required.
170
+
169
171
  Grape is available as a gem, to install it just install the gem:
170
172
 
171
173
  gem install grape
@@ -3226,7 +3228,7 @@ end
3226
3228
 
3227
3229
  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
3230
 
3229
- You can access the controller params, headers, and helpers through the context with the `#context` method inside any auth middleware inherited from `Grape::Middlware::Auth::Base`.
3231
+ 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
3232
 
3231
3233
  ## Describing and Inspecting an API
3232
3234
 
@@ -3540,7 +3542,7 @@ class API < Grape::API
3540
3542
  end
3541
3543
  ```
3542
3544
 
3543
- You can access the controller params, headers, and helpers through the context with the `#context` method inside any middleware inherited from `Grape::Middlware::Base`.
3545
+ 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
3546
 
3545
3547
  ### Rails Middleware
3546
3548
 
@@ -1,6 +1,49 @@
1
1
  Upgrading Grape
2
2
  ===============
3
3
 
4
+ ### Upgrading to >= 1.3.0
5
+
6
+ #### Ruby
7
+
8
+ After adding dry-types, Ruby 2.4 or newer is required.
9
+
10
+ #### Coercion
11
+
12
+ [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, explicitly add it to your `Gemfile`. Also, if Virtus is used for defining custom types
13
+
14
+ ```ruby
15
+ class User
16
+ include Virtus.model
17
+
18
+ attribute :id, Integer
19
+ attribute :name, String
20
+ end
21
+
22
+ # somewhere in your API
23
+ params do
24
+ requires :user, type: User
25
+ end
26
+ ```
27
+
28
+ Add a class-level `parse` method to the model:
29
+
30
+ ```ruby
31
+ class User
32
+ include Virtus.model
33
+
34
+ attribute :id, Integer
35
+ attribute :name, String
36
+
37
+ def self.parse(attrs)
38
+ new(attrs)
39
+ end
40
+ end
41
+ ```
42
+
43
+ Custom types which don't depend on Virtus don't require any changes.
44
+
45
+ For more information see [#1920](https://github.com/ruby-grape/grape/pull/1920).
46
+
4
47
  ### Upgrading to >= 1.2.4
5
48
 
6
49
  #### Headers in `error!` call
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
4
  require 'grape/version'
3
5
 
@@ -11,17 +13,24 @@ Gem::Specification.new do |s|
11
13
  s.summary = 'A simple Ruby framework for building REST-like APIs.'
12
14
  s.description = 'A Ruby framework for rapid API development with great conventions.'
13
15
  s.license = 'MIT'
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",
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}"
21
+ }
14
22
 
15
23
  s.add_runtime_dependency 'activesupport'
16
24
  s.add_runtime_dependency 'builder'
25
+ s.add_runtime_dependency 'dry-types', '>= 1.1'
17
26
  s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0'
18
27
  s.add_runtime_dependency 'rack', '>= 1.3.0'
19
28
  s.add_runtime_dependency 'rack-accept'
20
- s.add_runtime_dependency 'virtus', '>= 1.0.0'
21
29
 
22
30
  s.files = %w[CHANGELOG.md CONTRIBUTING.md README.md grape.png UPGRADING.md LICENSE]
23
31
  s.files += %w[grape.gemspec]
24
32
  s.files += Dir['lib/**/*']
25
33
  s.test_files = Dir['spec/**/*']
26
34
  s.require_paths = ['lib']
35
+ s.required_ruby_version = '>= 2.4.0'
27
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
  require 'rack'
3
5
  require 'rack/builder'
@@ -20,8 +22,6 @@ require 'active_support/notifications'
20
22
  require 'i18n'
21
23
  require 'thread'
22
24
 
23
- require 'virtus'
24
-
25
25
  I18n.load_path << File.expand_path('../grape/locale/en.yml', __FILE__)
26
26
 
27
27
  module Grape
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'grape/router'
2
4
  require 'grape/api/instance'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  class API
3
5
  module Helpers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'grape/router'
2
4
 
3
5
  module Grape
@@ -119,7 +121,7 @@ module Grape
119
121
  self.configuration = value_for_configuration
120
122
  response
121
123
  end
122
- if base_instance? && lazy
124
+ if base && base_instance? && lazy
123
125
  lazy_block
124
126
  else
125
127
  lazy_block.evaluate_from(configuration)
@@ -232,7 +234,7 @@ module Grape
232
234
  end
233
235
 
234
236
  attributes = config.merge(allowed_methods: allowed_methods, allow_header: allow_header)
235
- generate_not_allowed_method(config[:pattern], attributes)
237
+ generate_not_allowed_method(config[:pattern], **attributes)
236
238
  end
237
239
  end
238
240
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  module Config
3
5
  class Configuration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  class Cookies
3
5
  def initialize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  module DSL
3
5
  module Desc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  module DSL
3
5
  module Headers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -65,7 +67,7 @@ module Grape
65
67
 
66
68
  def define_boolean_in_mod(mod)
67
69
  return if defined? mod::Boolean
68
- mod.const_set('Boolean', Virtus::Attribute::Boolean)
70
+ mod.const_set('Boolean', Grape::API::Boolean)
69
71
  end
70
72
 
71
73
  def inject_api_helpers_to_mod(mod, &_block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
  require 'grape/dsl/headers'
3
5
 
@@ -28,7 +30,7 @@ module Grape
28
30
  module PostBeforeFilter
29
31
  def declared(passed_params, options = {}, declared_params = nil)
30
32
  options = options.reverse_merge(include_missing: true, include_parent_namespaces: true)
31
- declared_params ||= optioned_declared_params(options)
33
+ declared_params ||= optioned_declared_params(**options)
32
34
 
33
35
  if passed_params.is_a?(Array)
34
36
  declared_array(passed_params, options, declared_params)
@@ -84,7 +86,8 @@ module Grape
84
86
  end
85
87
 
86
88
  def declared_param_is_array?(declared_param)
87
- route_options_params[declared_param.to_s] && route_options_params[declared_param.to_s][:type] == 'Array'
89
+ key = declared_param.to_s
90
+ route_options_params[key] && route_options_params[key][:type] == 'Array'
88
91
  end
89
92
 
90
93
  def route_options_params
@@ -95,7 +98,7 @@ module Grape
95
98
  options[:stringify] ? declared_param.to_s : declared_param.to_sym
96
99
  end
97
100
 
98
- def optioned_declared_params(options)
101
+ def optioned_declared_params(**options)
99
102
  declared_params = if options[:include_parent_namespaces]
100
103
  # Declared params including parent namespaces
101
104
  route_setting(:saved_declared_params).flatten | Array(route_setting(:declared_params))
@@ -384,7 +387,7 @@ module Grape
384
387
  def entity_representation_for(entity_class, object, options)
385
388
  embeds = { env: env }
386
389
  embeds[:version] = env[Grape::Env::API_VERSION] if env[Grape::Env::API_VERSION]
387
- entity_class.represent(object, embeds.merge(options))
390
+ entity_class.represent(object, **embeds.merge(options))
388
391
  end
389
392
  end
390
393
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  module DSL
3
5
  module Logger
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -131,7 +133,7 @@ module Grape
131
133
  require_required_and_optional_fields(attrs.first, opts)
132
134
  else
133
135
  validate_attributes(attrs, opts, &block)
134
- block_given? ? new_scope(orig_attrs, &block) : push_declared_params(attrs, opts.slice(:as))
136
+ block_given? ? new_scope(orig_attrs, &block) : push_declared_params(attrs, **opts.slice(:as))
135
137
  end
136
138
  end
137
139
 
@@ -157,7 +159,7 @@ module Grape
157
159
  else
158
160
  validate_attributes(attrs, opts, &block)
159
161
 
160
- block_given? ? new_scope(orig_attrs, true, &block) : push_declared_params(attrs, opts.slice(:as))
162
+ block_given? ? new_scope(orig_attrs, true, &block) : push_declared_params(attrs, **opts.slice(:as))
161
163
  end
162
164
  end
163
165
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -20,7 +22,7 @@ module Grape
20
22
  if new_format
21
23
  namespace_inheritable(:format, new_format.to_sym)
22
24
  # define the default error formatters
23
- namespace_inheritable(:default_error_formatter, Grape::ErrorFormatter.formatter_for(new_format, {}))
25
+ namespace_inheritable(:default_error_formatter, Grape::ErrorFormatter.formatter_for(new_format, **{}))
24
26
  # define a single mime type
25
27
  mime_type = content_types[new_format.to_sym]
26
28
  raise Grape::Exceptions::MissingMimeType.new(new_format) unless mime_type
@@ -43,7 +45,7 @@ module Grape
43
45
  # Specify a default error formatter.
44
46
  def default_error_formatter(new_formatter_name = nil)
45
47
  if new_formatter_name
46
- new_formatter = Grape::ErrorFormatter.formatter_for(new_formatter_name, {})
48
+ new_formatter = Grape::ErrorFormatter.formatter_for(new_formatter_name, **{})
47
49
  namespace_inheritable(:default_error_formatter, new_formatter)
48
50
  else
49
51
  namespace_inheritable(:default_error_formatter)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -167,7 +169,7 @@ module Grape
167
169
  @namespace_description = (@namespace_description || {}).deep_merge(namespace_setting(:description) || {})
168
170
  nest(block) do
169
171
  if space
170
- namespace_stackable(:namespace, Namespace.new(space, options))
172
+ namespace_stackable(:namespace, Namespace.new(space, **options))
171
173
  end
172
174
  end
173
175
  @namespace_description = previous_namespace_description
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -169,7 +171,11 @@ module Grape
169
171
  # the superclass's :inheritable_setting.
170
172
  def build_top_level_setting
171
173
  Grape::Util::InheritableSetting.new.tap do |setting|
172
- if defined?(superclass) && superclass.respond_to?(:inheritable_setting) && superclass != Grape::API
174
+ # Doesn't try to inherit settings from +Grape::API::Instance+ which also responds to
175
+ # +inheritable_setting+, however, it doesn't contain any user-defined settings.
176
+ # Otherwise, it would lead to an extra instance of +Grape::Util::InheritableSetting+
177
+ # in the chain for every endpoint.
178
+ if defined?(superclass) && superclass.respond_to?(:inheritable_setting) && superclass != Grape::API::Instance
173
179
  setting.inherit_from superclass.inheritable_setting
174
180
  end
175
181
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
 
3
5
  module Grape
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Grape.eager_load!
2
4
  Grape::Http.eager_load!
3
5
  Grape::Exceptions.eager_load!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grape
2
4
  # An Endpoint is the proxy scope in which all routing
3
5
  # blocks are executed. In other words, any methods
@@ -154,8 +156,8 @@ module Grape
154
156
  methods << Grape::Http::Headers::HEAD
155
157
  end
156
158
  methods.each do |method|
157
- unless route.request_method.to_s.upcase == method
158
- route = Grape::Router::Route.new(method, route.origin, route.attributes.to_h)
159
+ unless route.request_method == method
160
+ route = Grape::Router::Route.new(method, route.origin, **route.attributes.to_h)
159
161
  end
160
162
  router.append(route.apply(self))
161
163
  end
@@ -167,8 +169,8 @@ module Grape
167
169
  route_options = prepare_default_route_attributes
168
170
  map_routes do |method, path|
169
171
  path = prepare_path(path)
170
- params = merge_route_options(route_options.merge(suffix: path.suffix))
171
- route = Router::Route.new(method, path.path, params)
172
+ params = merge_route_options(**route_options.merge(suffix: path.suffix))
173
+ route = Router::Route.new(method, path.path, **params)
172
174
  route.apply(self)
173
175
  end.flatten
174
176
  end
@@ -260,7 +262,7 @@ module Grape
260
262
  run_validators validations, request
261
263
  remove_renamed_params
262
264
  run_filters after_validations, :after_validation
263
- response_object = @block ? @block.call(self) : nil
265
+ response_object = execute
264
266
  end
265
267
 
266
268
  run_filters afters, :after
@@ -333,6 +335,10 @@ module Grape
333
335
 
334
336
  private :build_stack, :build_helpers, :remove_renamed_params
335
337
 
338
+ def execute
339
+ @block ? @block.call(self) : nil
340
+ end
341
+
336
342
  def helpers
337
343
  lazy_initialize! && @helpers
338
344
  end
@@ -353,7 +359,7 @@ module Grape
353
359
  def run_validators(validator_factories, request)
354
360
  validation_errors = []
355
361
 
356
- validators = validator_factories.map { |options| Grape::Validations::ValidatorFactory.create_validator(options) }
362
+ validators = validator_factories.map { |options| Grape::Validations::ValidatorFactory.create_validator(**options) }
357
363
 
358
364
  ActiveSupport::Notifications.instrument('endpoint_run_validators.grape', endpoint: self, validators: validators, request: request) do
359
365
  validators.each do |validator|
@@ -369,7 +375,7 @@ module Grape
369
375
  end
370
376
  end
371
377
 
372
- validation_errors.any? && raise(Grape::Exceptions::ValidationErrors, errors: validation_errors, headers: header)
378
+ validation_errors.any? && raise(Grape::Exceptions::ValidationErrors.new(errors: validation_errors, headers: header))
373
379
  end
374
380
 
375
381
  def run_filters(filters, type = :other)