问题
let obj = Joi.object().keys({
"id": Joi.string().required(),
"array": Joi.array().items(obj).required()//array contains multiple
});
is there any way to define recursive array validation in JOI obj.array contains n number of obj
回答1:
Recursive schemas can be achieved using Joi's lazy(fn) function. The following example from the documentation can be adapted to your schema however I'm not sure how you'd be able to define a max depth.
const Person = Joi.object({
firstName: Joi.string().required(),
lastName: Joi.string().required(),
children: Joi.array().items(Joi.lazy(() => Person).description('Person schema'))
});
来源:https://stackoverflow.com/questions/51477603/using-joi-how-to-define-recursive-array-of-objects-validation-with-n-depth