Closed zelid closed 2 years ago
Please try Joiful's custom
decorator. This gives you access to the Joi instance, exposing more of the original Joi API.
Rough example:
class PersonalAccount {
@jf.custom((Joi) => Joi.alternatives().conditional('type', { is: 1, then: Joi.string().required() }))
firstname?: string;
}
(This is similar to #216)
Hello,
I have a need to make some properties mandatory depending on other properties. For example if country is US or CA than state is mandatory.
Joi has support through
Joi.alternatives().conditional
As I understand such decorator is not available with
Joiful
but what could be suitable way to validate conditions? Maybe read schema likeconst schema = jf.getSchema(Order)
and extend it somehow with conditions.Any help with ideas how to use both
Joiful
decorators for simple cases and extend special cases like conditions before performing POST body validation with:Thanks for any ideas and suggestions.