【发布时间】:2021-07-23 03:12:24
【问题描述】:
我想使用 Joi 实现以下验证。
我的架构:
const schema = Joi.object({
createdDate: Joi.string().required(),
futureDate: Joi.string().allow("").optional(),
Events: Joi.array().items({
status: Joi.string().required(),
type: Joi.string().required()
})
});
我的输入请求将是这样的。我正在使用上述架构和验证验证以下请求。如果Events.type == "XYZ" 则futureDate 是必需的,否则它是可选的。
{
"createdDate": "2021-02-02T00:00:00",
"futureDate": "2021-02-02T00:00:00",
"Events": [
{
"status": "P",
"type": "ABC"
},
{
"status": "S",
"type": "XYZ"
}
]
}
【问题讨论】:
标签: typescript joi