-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Summary
joi v17.0.0 is a small maintenance release in sync with the upcoming hapi v19 release. The main changes include dropping support for all versions of node prior to v12 and small changes to the configuration and generation of error messages.
- Upgrade time: low - changes are well contained
- Complexity: low - changes are easy to apply
- Risk: low - small number of changes with obvious outcome if not applied correctly
- Dependencies: low - no changes to the extension system
Breaking Changes
- Apply quotation marks around labels in error messages based on config instead of literal quotes in the error message (Remove quotation marks from error messages #2182)
- Change default function second argument to full helpers from just prefs (Change default function second argument to full helpers (from prefs) #2189)
- Remove support for node v8 and v10 (Remove node 8, 10 #2199)
- Change
errors.wrapArraystoerrors.wrap.array(Change errors.wrapArrays to errors.wrap.array #2231) - Remove ValidationError.annotate() from browser build (Remove ValidationError.annotate() from browser build #2261)
Bug fixes
- Allow
_in rule names (except first character) (Can you allow_in rule names? #2242) - Fix
any.valid()incorrect error message on array argument (Giving an array argument to any.valid returns incorrect error #2254)
Updated dependencies
- address from v2.x to v4.x
- formula from v1.x to v2.x
- hoek from v8.x to v9.x
- pinpoint from v1.x to v2.x
- topo from v3.x to v5.x
New Features
- Support international domain validation in
string.hostname()(string().hostiname() - validation of non-ASCII chars containing domains #2163) - Add the ability to extend multiple types with same rules (Add the ability to extend all types in place #2219)
object.regex()(object.regex() #2260)- Customize wrapping of labels and arrays in error messages (Change errors.wrapArrays to errors.wrap.array #2231)
Migration Checklist
Error messages
Instead of wrapping labels in quotes in the error message literal string, the quotes are not added in message generation based on new preferences. For example:
The previous message '"{{#label}}" is not allowed' is now '{{#label}} is not allowed' but the result is the same for all internal messages as the " are added by default.
This will break any custom message defined outside of joi by adding a set of quotes regardless if the message literal string already contains them.
In addition, the errors.wrapArrays preference was changed to errors.wrap.array which now accepts a string (of 1 or 2 characters) or false. If false is provided, no wrapping is performed. If a single character string is provided, that character is used before and after the value. If a two characters string is provided, the first will be used before the value and the second after the value. For example, '12' will cause the array ['a','b'] to be wrapped '1a,b2'.
A new setting errors.wrap.label controls wrapping of labels in quotes with the same options as errors.wrap.array.
Checklist:
- Review all custom error messages containing
{label}or{{label}}and ensure to remove any existing quotes. If no quotes are used, make sure to set theerrors.wrap.labelpreference tofalse. - Change
errors.wrapArraystoerrors.wrap.array.
any.default() function value signature
When a function is provided to generate default values, the function signature has changed from function(parent, prefs) to function(parent, helpers). The second argument was not documented in previous versions.
Checklist:
- Look for
.default()calls in your code and if a function with more than one argument is provided, change the second argument fromprefsto{ prefs }which will provide the same value.