最佳答案
试图验证一个数组在一种情况下有零个或多个字符串,而在另一种情况下有零个或多个对象,这与 Joi docs 有些矛盾: (
validate: {
headers: Joi.object({
'content-type': "application/vnd.api+json",
accept: "application/vnd.api+json"
}).options({ allowUnknown: true }),
payload : Joi.object().keys({
data : Joi.object().keys({
type: Joi.any().allow('BY_TEMPLATE').required(),
attributes: Joi.object({
to : Joi.string().email().required(),
templateId : Joi.string().required(),
categories : Joi.array().items( //trying to validate here that each element is a string),
variables : Joi.array({
//also trying to validate here that each element is an Object with one key and value
})
})
}).required()
})
}