-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Summary
This release should be low impact but necessary to fix the alternatives that many are complaining about.
- Upgrade time: probably none
- Complexity: none
- Risk: low
Breaking changes
Alternatives
Previously, alternatives using multiple whens attempted every possibility until one fully succeeded, meaning that if the is matched (or didn't) but the then (or otherwise) failed, it would keep going, making some use cases impossible to achieve.
Now alternatives will behave pretty much like you thought it were, if is matches, the corresponding schema will be evaluated, unless there is none in which case the next alternative will run.
Note an alternative with both then and otherwise will obviously end the chain as there is no other path possible.
any().describe()
Previous version of describe (which is still not documented, sorry) outputted references sometimes as functions, sometimes as strings ('ref:a.b), it is now consistently returning the 2nd form.
New features
any().when()
when used in the context of a schema can now be used multiple times without having to make an alternative out of it. So the following schema will now work :
const schema = Joi.object({
a: Joi.number().required(),
b: Joi.number()
.when('a', { is: 1, then: Joi.number().valid(1) })
.when('a', { is: 2, then: Joi.number().valid(2) })
.when('a', { is: 3, then: Joi.number().valid(3) })
});Meaning that when a is 1, 2 or 3, b if present takes the same value, otherwise it has to be a number.
assert()
The stack traces printed by assert ignored the fact that Infinity, -Infinity and NaN couldn't be stringified. It will now show them correctly.
Contributors
The contributors to this release are @mdibaiee and myself.