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
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
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 the errors.wrap.label preference to false.
Change errors.wrapArrays to errors.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 from prefs to { prefs } which will provide the same value.
The text was updated successfully, but these errors were encountered:
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.
Breaking Changes
errors.wrapArrays
toerrors.wrap.array
(Change errors.wrapArrays to errors.wrap.array #2231)Bug fixes
_
in rule names (except first character) (Can you allow_
in rule names? #2242)any.valid()
incorrect error message on array argument (Giving an array argument to any.valid returns incorrect error #2254)Updated dependencies
New Features
string.hostname()
(string().hostiname() - validation of non-ASCII chars containing domains #2163)object.regex()
(object.regex() #2260)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 toerrors.wrap.array
which now accepts a string (of 1 or 2 characters) orfalse
. Iffalse
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 aserrors.wrap.array
.Checklist:
{label}
or{{label}}
and ensure to remove any existing quotes. If no quotes are used, make sure to set theerrors.wrap.label
preference tofalse
.errors.wrapArrays
toerrors.wrap.array
.any.default()
function value signatureWhen a function is provided to generate default values, the function signature has changed from
function(parent, prefs)
tofunction(parent, helpers)
. The second argument was not documented in previous versions.Checklist:
.default()
calls in your code and if a function with more than one argument is provided, change the second argument fromprefs
to{ prefs }
which will provide the same value.The text was updated successfully, but these errors were encountered: