You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Store validator instances in ParamsScope/ContractScope and have
Endpoint#run_validators read them directly
- Remove ValidatorFactory indirection and eagerly compute validator
messages/options in constructors
- Extract Grape::Util::Translation module shared by Exceptions::Base
and Validators::Base for I18n translate with fallback locale
- Support Hash messages in translate_message for deferred translation
with interpolation parameters (e.g. { key: :length, min: 2 })
- Normalize Grape::Exceptions::Validation params handling and refactor
validator specs to define routes per example group
- Drop test-prof dependency and its spec config
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: UPGRADING.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,70 @@
1
1
Upgrading Grape
2
2
===============
3
3
4
+
### Upgrading to >= 3.2
5
+
6
+
#### Validators Instantiated at Compile Time
7
+
8
+
Previously, validators were instantiated at request time but they are now instantiated at compile time. Validators are thread safe since their initial state always stay the same. It also reduces object allocations overtime since instances are reused.
9
+
10
+
#### `Grape::Exceptions::Validation` Changes
11
+
12
+
**`params` and `message_key` are now read-only.**`attr_accessor` has been changed to `attr_reader`. If you were assigning to these after initialization, set them via the constructor keyword arguments instead.
13
+
14
+
**`params` is now always coerced to an array.** You can now pass a single string instead of wrapping it in an array:
The following methods on `Grape::Validations::Validators::Base` are now **private**: `validate!`, `message`, `options_key?`. If your custom validator subclass calls these via `super` from a private method, no change is needed. If you were calling them from outside the class, you'll need to adjust.
-`option_value` — returns `@option[:value]` if present, otherwise `@option`
32
+
-`scrub(value)` — scrubs invalid-encoding strings
33
+
34
+
#### `Validators::Base#message` Now Accepts a Block
35
+
36
+
`message` now accepts an optional block for lazy default message generation. The block is only called when no custom `:message` option is set and no `default_key` is provided:
If your custom validator overrides `message` or passes a `default_key`, the behavior is unchanged. If you relied on `message` returning `nil` when no custom message and no default key were set, it now yields to the block instead.
51
+
52
+
#### `ContractScopeValidator` No Longer Inherits from `Base`
53
+
54
+
`ContractScopeValidator` is now a standalone class that no longer inherits from `Grape::Validations::Validators::Base`. Its constructor takes a single `schema:` keyword argument instead of the standard 5-argument validator signature:
All built-in validators now eagerly compute and cache values in their constructors (exception messages, option values, lambdas for proc-based defaults/values). This is transparent to API consumers but relevant if you subclass built-in validators and override `initialize` — ensure you call `super` so caching is properly set up.
67
+
4
68
### Upgrading to >= 3.1
5
69
6
70
#### Explicit kwargs for `namespace` and `route_param`
0 commit comments