【发布时间】:2018-05-30 12:09:27
【问题描述】:
我有以下验证架构和示例数据。
var schema = Joi.alternatives().try(
Joi.object().keys({
searchTerm: Joi.string().trim().min(3).label('Search Term').options({ language: { any: { empty: 'should not be empty' } } }),
location: Joi.string().allow(''),
searchType: Joi.string().valid('people')
}),
Joi.object().keys({
searchTerm: Joi.string().allow(''),
location: Joi.string().trim().min(3).label('Location').options({ language: { any: { empty: 'should not be empty' } } }),
searchType: Joi.string().valid('people')
})
);
样本数据是:
{searchTerm: "", searchType: "people", location: ""}
不应通过并显示消息Please enter either search term or location. Make sure it contains 3 characters at least
{searchTerm: "as", searchType: "people", location: ""}
不应通过并显示消息Search term must contain 3 characters at least
{searchTerm: "test", searchType: "people", location: ""} // Should pass
我的验证模式在失败情况下显示两条消息
【问题讨论】:
标签: node.js validation joi