[英]Multiple Joi validation types
I search a lot but nothing found to allow multiple type validation in Joi
我搜索了很多,但没有发现允许在Joi
进行多种类型验证
Link: https://github.com/hapijs/joi 链接: https : //github.com/hapijs/joi
I would like to use something like this: 我想用这样的东西:
validate: {
type: joi.or([
joi.string(),
joi.array(),
])
};
Try: 尝试:
validate: {
type: joi.alternatives().try(joi.string(), joi.array())
}
or: 要么:
validate: {
type: [joi.string(), joi.array()]
}
See: https://github.com/hapijs/joi/blob/v10.1.0/API.md#alternatives 请参阅: https : //github.com/hapijs/joi/blob/v10.1.0/API.md#alternatives
export const saveDeviceCommandsSchema = {
devices: [
Joi.array().items(Joi.string().required()).required(),
Joi.string().valid('all').required().lowercase()
],
info: Joi.array()
}; }; example specifying more than a validation rule to an object 为对象指定多于验证规则的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.