【发布时间】:2018-01-18 14:59:26
【问题描述】:
我正在使用 hapijs 编写微服务。我有一个在请求正文中采用三个参数的 API(POST 方法)
- 用户ID
- 姓氏
- 出生日期
我打算使用 JOI 进行验证。验证应该如下
如果姓氏和出生日期都是 请求中不存在
如果没有 UserID,则需要同时填写姓氏和出生日期
我试图通过以下方式实现这一目标。它似乎不起作用。
export const userRequestModel = Joi.object().keys({
lastname: Joi.string().when('uid',
{
is: undefined,
then: Joi.string().required()
}),
dob: Joi.string().when('uid',
{
is: undefined,
then: Joi.string().required()
}),
uid: Joi.string().
when('lastname',
{
is: undefined,
then: Joi.string().required()
}).
concat(Joi.string().when('dob',
{
is: undefined,
then: Joi.string().required()
}))
});
连接似乎在语法上不正确。它显示以下输入错误
“AlternativesSchema”类型的参数不可分配给“FunctionSchema”类型的参数。“AlternativesSchema”类型中缺少属性“arity”。
【问题讨论】:
标签: typescript hapijs joi