|
1 | 1 | Upgrading Grape |
2 | 2 | =============== |
3 | 3 |
|
| 4 | +### Upgrading to >= 2.4.0 |
| 5 | + |
| 6 | +#### Grape::Middleware::Auth::Base |
| 7 | +`type` is now validated at compile time and will raise a `Grape::Exceptions::UnknownAuthStrategy` if unknown. |
| 8 | + |
| 9 | +#### Grape::Middleware::Base |
| 10 | + |
| 11 | +- Second argument `options` is now a double splat (**) instead of single splat (*). If you're redefining `initialize` in your middleware and/or calling `super` in it, you might have to adapt the signature and the `super` call. Also, you might have to remove `{}` if you're pass `options` as a literal `Hash` or add `**` if you're using a variable. |
| 12 | +- `Grape::Middleware::Helpers` has been removed. The equivalent method `context` is now part of `Grape::Middleware::Base`. |
| 13 | + |
| 14 | +#### Grape::Http::Headers, Grape::Util::Lazy::Object |
| 15 | + |
| 16 | +Both have been removed. See [2554](https://github.com/ruby-grape/grape/pull/2554). |
| 17 | +Here are the notable changes: |
| 18 | + |
| 19 | +- Constants like `HTTP_ACCEPT` have been replaced by their literal value. |
| 20 | +- `SUPPORTED_METHODS` has been moved to `Grape` module. |
| 21 | +- `HTTP_HEADERS` has been moved to `Grape::Request` and renamed `KNOWN_HEADERS`. The last has been refreshed with new headers, and it's not lazy anymore. |
| 22 | +- `SUPPORTED_METHODS_WITHOUT_OPTIONS` and `find_supported_method` have been removed. |
| 23 | + |
| 24 | +#### Grape::Middleware::Base |
| 25 | + |
| 26 | +- Constant `TEXT_HTML` has been removed in favor of using literal string 'text/html'. |
| 27 | +- `rack_request` and `query_params` have been added. Feel free to call these in your middlewares. |
| 28 | + |
4 | 29 | #### Params Builder |
5 | 30 |
|
6 | 31 | - Passing a class to `build_with` or `Grape.config.param_builder` has been deprecated in favor of a symbolized short_name. See `SHORTNAME_LOOKUP` in [params_builder](lib/grape/params_builder.rb). |
7 | 32 | - Including Grape's extensions like `Grape::Extensions::Hashie::Mash::ParamBuilder` has been deprecated in favor of using `build_with` at the route level. |
8 | 33 |
|
9 | | -### Upgrading to >= 2.4.0 |
| 34 | +#### Accept Header Negotiation Harmonized |
| 35 | + |
| 36 | +[Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept) header is now fully interpreted through `Rack::Utils.best_q_match` which is following [RFC2616 14.1](https://datatracker.ietf.org/doc/html/rfc2616#section-14.1). Since [Grape 2.1.0](https://github.com/ruby-grape/grape/blob/master/CHANGELOG.md#210-20240615), the [header versioning strategy](https://github.com/ruby-grape/grape?tab=readme-ov-file#header) was adhering to it, but `Grape::Middleware::Formatter` never did. |
| 37 | + |
| 38 | +Your API might act differently since it will strictly follow the [RFC2616 14.1](https://datatracker.ietf.org/doc/html/rfc2616#section-14.1) when interpreting the `Accept` header. Here are the differences: |
| 39 | + |
| 40 | +##### Invalid or missing quality ranking |
| 41 | +The following used to yield `application/xml` and now will yield `application/json` as the preferred media type: |
| 42 | +- `application/json;q=invalid,application/xml;q=0.5` |
| 43 | +- `application/json,application/xml;q=1.0` |
| 44 | + |
| 45 | +For the invalid case, the value `invalid` was automatically `to_f` and `invalid.to_f` equals `0.0`. Now, since it doesn't match [Rack's regex](https://github.com/rack/rack/blob/3-1-stable/lib/rack/utils.rb#L138), its interpreted as non provided and its quality ranking equals 1.0. |
| 46 | + |
| 47 | +For the non provided case, 1.0 was automatically assigned and in a case of multiple best matches, the first was returned based on Ruby's sort_by `quality`. Now, 1.0 is still assigned and the last is returned in case of multiple best matches. See [Rack's implementation](https://github.com/rack/rack/blob/e8f47608668d507e0f231a932fa37c9ca551c0a5/lib/rack/utils.rb#L167) of the RFC. |
| 48 | + |
| 49 | +##### Considering the closest generic when vendor tree |
| 50 | +Excluding the [header versioning strategy](https://github.com/ruby-grape/grape?tab=readme-ov-file#header), whenever a media type with the [vendor tree](https://datatracker.ietf.org/doc/html/rfc6838#section-3.2) leading facet `vnd.` like `application/vnd.api+json` was provided, Grape would also consider its closest generic when negotiating. In that case, `application/json` was added to the negotiation. Now, it will just consider the provided media types without considering any closest generics, and you'll need to [register](https://github.com/ruby-grape/grape?tab=readme-ov-file#api-formats) it. |
| 51 | +You can find the official vendor tree registrations on [IANA](https://www.iana.org/assignments/media-types/media-types.xhtml) |
10 | 52 |
|
11 | 53 | #### Custom Validators |
12 | 54 |
|
@@ -96,7 +138,7 @@ When using together with `Grape::Extensions::Hash::ParamBuilder`, `route_param` |
96 | 138 | This was a regression introduced by [#2326](https://github.com/ruby-grape/grape/pull/2326) in Grape v1.8.0. |
97 | 139 |
|
98 | 140 | ```ruby |
99 | | -grape.configure do |config| |
| 141 | +Grape.configure do |config| |
100 | 142 | config.param_builder = Grape::Extensions::Hash::ParamBuilder |
101 | 143 | end |
102 | 144 |
|
|
0 commit comments