Skip to content

Commit 96dc556

Browse files
committed
Merge branch 'master' into revisit_coerce_and_validator
2 parents 315deba + 67ea152 commit 96dc556

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1252
-621
lines changed

.rubocop_todo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-10-06 16:00:59 UTC using RuboCop version 1.66.1.
3+
# on 2025-02-23 19:41:28 UTC using RuboCop version 1.71.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -60,7 +60,7 @@ RSpec/IndexedLet:
6060
- 'spec/grape/presenters/presenter_spec.rb'
6161
- 'spec/shared/versioning_examples.rb'
6262

63-
# Offense count: 38
63+
# Offense count: 39
6464
# Configuration parameters: AssignmentOnly.
6565
RSpec/InstanceVariable:
6666
Exclude:

CHANGELOG.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
### 2.3.0 (Next)
1+
### 2.4.0 (Next)
2+
3+
#### Features
4+
5+
* [#2532](https://github.com/ruby-grape/grape/pull/2532): Update RuboCop 1.71.2 - [@ericproulx](https://github.com/ericproulx).
6+
* [#2535](https://github.com/ruby-grape/grape/pull/2535): Delegates calls to inner objects - [@ericproulx](https://github.com/ericproulx).
7+
* [#2537](https://github.com/ruby-grape/grape/pull/2537): Use activesupport `try` pattern - [@ericproulx](https://github.com/ericproulx).
8+
* [#2536](https://github.com/ruby-grape/grape/pull/2536): Update normalize_path like Rails - [@ericproulx](https://github.com/ericproulx).
9+
* [#2540](https://github.com/ruby-grape/grape/pull/2540): Introduce Params builder with symbolized short name - [@ericproulx](https://github.com/ericproulx).
10+
* [#2550](https://github.com/ruby-grape/grape/pull/2550): Drop ActiveSupport 6.0 - [@ericproulx](https://github.com/ericproulx).
11+
* [#2549](https://github.com/ruby-grape/grape/pull/2549): Delegate cookies management to `Grape::Request` - [@ericproulx](https://github.com/ericproulx).
12+
* Your contribution here.
13+
14+
#### Fixes
15+
16+
* [#2538](https://github.com/ruby-grape/grape/pull/2538): Fix validating nested json array params - [@mohammednasser-32](https://github.com/mohammednasser-32).
17+
* [#2543](https://github.com/ruby-grape/grape/pull/2543): Fix array allocation on mount - [@ericproulx](https://github.com/ericproulx).
18+
* [#2546](https://github.com/ruby-grape/grape/pull/2546): Fix middleware with keywords - [@ericproulx](https://github.com/ericproulx).
19+
* [#2547](https://github.com/ruby-grape/grape/pull/2547): Remove jsonapi related code - [@ericproulx](https://github.com/ericproulx).
20+
* [#2548](https://github.com/ruby-grape/grape/pull/2548): Formatting from header acts like versioning from header - [@ericproulx](https://github.com/ericproulx).
21+
* [#2552](https://github.com/ruby-grape/grape/pull/2552): Fix declared params optional array - [@ericproulx](https://github.com/ericproulx).
22+
* Your contribution here.
23+
24+
### 2.3.0 (2025-02-08)
225

326
#### Features
427

@@ -11,15 +34,18 @@
1134
* [#2514](https://github.com/ruby-grape/grape/pull/2514): Add rails 8.0 to CI - [@ericproulx](https://github.com/ericproulx).
1235
* [#2516](https://github.com/ruby-grape/grape/pull/2516): Dynamic registration for parsers, formatters, versioners - [@ericproulx](https://github.com/ericproulx).
1336
* [#2518](https://github.com/ruby-grape/grape/pull/2518): Add ruby 3.4 to CI - [@ericproulx](https://github.com/ericproulx).
14-
* Your contribution here.
1537

1638
#### Fixes
1739

1840
* [#2504](https://github.com/ruby-grape/grape/pull/2504): Fix leaky modules in specs - [@ericproulx](https://github.com/ericproulx).
1941
* [#2506](https://github.com/ruby-grape/grape/pull/2506): Fix fetch_formatter api_format - [@ericproulx](https://github.com/ericproulx).
2042
* [#2507](https://github.com/ruby-grape/grape/pull/2507): Fix type: Set with values - [@nikolai-b](https://github.com/nikolai-b).
2143
* [#2510](https://github.com/ruby-grape/grape/pull/2510): Fix ContractScope's validator inheritance - [@ericproulx](https://github.com/ericproulx).
22-
* Your contribution here.
44+
* [#2521](https://github.com/ruby-grape/grape/pull/2521): Fixed typo in README - [@datpmt](https://github.com/datpmt).
45+
* [#2525](https://github.com/ruby-grape/grape/pull/2525): Require logger before active_support - [@ericproulx](https://github.com/ericproulx).
46+
* [#2524](https://github.com/ruby-grape/grape/pull/2524): Fix validators bad encoding - [@ericproulx](https://github.com/ericproulx).
47+
* [#2530](https://github.com/ruby-grape/grape/pull/2530): Fix endpoint's status when rescue_from without a block - [@ericproulx](https://github.com/ericproulx).
48+
* [#2529](https://github.com/ruby-grape/grape/pull/2529): Fix missing settings on mounted routes (when settings are identical) - [@Haerezis](https://github.com/Haerezis).
2349

2450
### 2.2.0 (2024-09-14)
2551

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Contributing to Grape
22
=====================
33

4-
Grape is work of [hundreds of contributors](https://github.com/ruby-grape/grape/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/ruby-grape/grape/pulls), [propose features and discuss issues](https://github.com/ruby-grape/grape/issues). When in doubt, ask a question in the [Grape Google Group](http://groups.google.com/group/ruby-grape).
4+
Grape is work of [hundreds of contributors](https://github.com/ruby-grape/grape/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/ruby-grape/grape/pulls), [propose features and discuss issues](https://github.com/ruby-grape/grape/issues).
55

66
#### Fork the Project
77

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ group :development, :test do
1010
gem 'builder', require: false
1111
gem 'bundler'
1212
gem 'rake'
13-
gem 'rubocop', '1.66.1', require: false
14-
gem 'rubocop-performance', '1.21.1', require: false
15-
gem 'rubocop-rspec', '3.0.5', require: false
13+
gem 'rubocop', '1.71.2', require: false
14+
gem 'rubocop-performance', '1.23.1', require: false
15+
gem 'rubocop-rspec', '3.4.0', require: false
1616
end
1717

1818
group :development do

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
![grape logo](grape.png)
22

33
[![Gem Version](https://badge.fury.io/rb/grape.svg)](http://badge.fury.io/rb/grape)
4-
[![Build Status](https://github.com/ruby-grape/grape/workflows/test/badge.svg?branch=master)](https://github.com/ruby-grape/grape/actions)
5-
[![Code Climate](https://codeclimate.com/github/ruby-grape/grape.svg)](https://codeclimate.com/github/ruby-grape/grape)
4+
[![test](https://github.com/ruby-grape/grape/actions/workflows/test.yml/badge.svg)](https://github.com/ruby-grape/grape/actions/workflows/test.yml)
65
[![Coverage Status](https://coveralls.io/repos/github/ruby-grape/grape/badge.svg?branch=master)](https://coveralls.io/github/ruby-grape/grape?branch=master)
7-
[![Inline docs](https://inch-ci.org/github/ruby-grape/grape.svg)](https://inch-ci.org/github/ruby-grape/grape)
8-
[![Join the chat at https://gitter.im/ruby-grape/grape](https://badges.gitter.im/ruby-grape/grape.svg)](https://gitter.im/ruby-grape/grape?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
96

107
## Table of Contents
118

@@ -157,14 +154,14 @@ Grape is a REST-like API framework for Ruby. It's designed to run on Rack or com
157154

158155
## Stable Release
159156

160-
You're reading the documentation for the next release of Grape, which should be 2.3.0.
161-
The current stable release is [2.2.0](https://github.com/ruby-grape/grape/blob/v2.2.0/README.md).
157+
You're reading the documentation for the next release of Grape, which should be 2.4.0.
158+
The current stable release is [2.3.0](https://github.com/ruby-grape/grape/blob/v2.3.0/README.md).
162159

163160
## Project Resources
164161

165162
* [Grape Website](http://www.ruby-grape.org)
166163
* [Documentation](http://www.rubydoc.info/gems/grape)
167-
* Need help? Try [Grape Google Group](http://groups.google.com/group/ruby-grape) or [Gitter](https://gitter.im/ruby-grape/grape)
164+
* Need help? [Open an Issue](https://github.com/ruby-grape/grape/issues)
168165
* [Follow us on Twitter](https://twitter.com/grapeframework)
169166

170167
## Grape for Enterprise
@@ -719,10 +716,13 @@ For example, for the `param_builder`, the following code could run in an initial
719716

720717
```ruby
721718
Grape.configure do |config|
722-
config.param_builder = Grape::Extensions::Hashie::Mash::ParamBuilder
719+
config.param_builder = :hashie_mash
723720
end
724721
```
725722

723+
Available parameter builders are `:hash`, `:hash_with_indifferent_access`, and `:hashie_mash`.
724+
See [params_builder](lib/grape/params_builder).
725+
726726
You can also configure a single API:
727727

728728
```ruby
@@ -789,7 +789,7 @@ By default parameters are available as `ActiveSupport::HashWithIndifferentAccess
789789

790790
```ruby
791791
class API < Grape::API
792-
include Grape::Extensions::Hashie::Mash::ParamBuilder
792+
build_with :hashie_mash
793793

794794
params do
795795
optional :color, type: String
@@ -803,16 +803,15 @@ The class can also be overridden on individual parameter blocks using `build_wit
803803

804804
```ruby
805805
params do
806-
build_with Grape::Extensions::Hash::ParamBuilder
806+
build_with :hash
807807
optional :color, type: String
808808
end
809809
```
810810

811-
Or globally with the [Configuration](#configuration) `Grape.configure.param_builder`.
812-
813811
In the example above, `params["color"]` will return `nil` since `params` is a plain `Hash`.
814812

815-
Available parameter builders are `Grape::Extensions::Hash::ParamBuilder`, `Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder` and `Grape::Extensions::Hashie::Mash::ParamBuilder`.
813+
Available parameter builders are `:hash`, `:hash_with_indifferent_access`, and `:hashie_mash`.
814+
See [params_builder](lib/grape/params_builder).
816815

817816
### Declared
818817

@@ -2046,7 +2045,7 @@ end
20462045
```ruby
20472046
params do
20482047
requires :code, type: String, length: { is: 2, message: 'code is expected to be exactly 2 characters long' }
2049-
requires :str, type: String, length: { min: 5, message: 'str is expected to be atleast 5 characters long' }
2048+
requires :str, type: String, length: { min: 5, message: 'str is expected to be at least 5 characters long' }
20502049
requires :list, type: [Integer], length: { min: 2, max: 3, message: 'list is expected to have between 2 and 3 elements' }
20512050
end
20522051
```
@@ -3536,8 +3535,8 @@ Please use `Route#xyz` instead.
35363535

35373536
Note that difference of `Route#options` and `Route#settings`.
35383537

3539-
The `options` can be referred from your route, it should be set by specifing key and value on verb methods such as `get`, `post` and `put`.
3540-
The `settings` can also be referred from your route, but it should be set by specifing key and value on `route_setting`.
3538+
The `options` can be referred from your route, it should be set by specifying key and value on verb methods such as `get`, `post` and `put`.
3539+
The `settings` can also be referred from your route, but it should be set by specifying key and value on `route_setting`.
35413540

35423541
## Current Route and Endpoint
35433542

UPGRADING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
Upgrading Grape
22
===============
33

4+
#### Params Builder
5+
6+
- 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+
- Including Grape's extensions like `Grape::Extensions::Hashie::Mash::ParamBuilder` has been deprecated in favor of using `build_with` at the route level.
8+
9+
#### Accept Header Negotiation Harmonized
10+
11+
[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.
12+
13+
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:
14+
15+
###### Invalid or missing quality ranking
16+
The following used to yield `application/xml` and now will yield `application/json` as the preferred media type:
17+
- `application/json;q=invalid,application/xml;q=0.5`
18+
- `application/json,application/xml;q=1.0`
19+
20+
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.
21+
22+
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.
23+
24+
###### Considering the closest generic when vendor tree
25+
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.
26+
You can find the official vendor tree registrations on [IANA](https://www.iana.org/assignments/media-types/media-types.xhtml)
27+
28+
### Upgrading to >= 2.4.0
29+
30+
#### Custom Validators
31+
32+
If you now receive an error of `'Grape::Validations.require_validator': unknown validator: your_custom_validation (Grape::Exceptions::UnknownValidator)` after upgrading to 2.4.0 then you will need to ensure that you require the `your_custom_validation` file before your Grape API code is loaded.
33+
34+
See [2533](https://github.com/ruby-grape/grape/issues/2533) for more information.
35+
436
### Upgrading to >= 2.3.0
537

638
### `content_type` vs `api.format` inside API

grape.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
2121
'rubygems_mfa_required' => 'true'
2222
}
2323

24-
s.add_dependency 'activesupport', '>= 6'
24+
s.add_dependency 'activesupport', '>= 6.1'
2525
s.add_dependency 'dry-types', '>= 1.1'
2626
s.add_dependency 'mustermann-grape', '~> 1.1.0'
2727
s.add_dependency 'rack', '>= 2'

lib/grape.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'logger'
34
require 'active_support'
45
require 'active_support/concern'
56
require 'active_support/configurable'
@@ -19,6 +20,7 @@
1920
require 'active_support/core_ext/module/delegation'
2021
require 'active_support/core_ext/object/blank'
2122
require 'active_support/core_ext/object/deep_dup'
23+
require 'active_support/core_ext/object/try'
2224
require 'active_support/core_ext/object/duplicable'
2325
require 'active_support/core_ext/string/output_safety'
2426
require 'active_support/core_ext/string/exclude'
@@ -33,7 +35,6 @@
3335
require 'dry-types'
3436
require 'forwardable'
3537
require 'json'
36-
require 'logger'
3738
require 'mustermann/grape'
3839
require 'pathname'
3940
require 'rack'
@@ -63,7 +64,7 @@ def self.deprecator
6364
end
6465

6566
configure do |config|
66-
config.param_builder = Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder
67+
config.param_builder = :hash_with_indifferent_access
6768
config.compile_methods!
6869
end
6970
end

0 commit comments

Comments
 (0)