【发布时间】:2018-04-23 18:37:05
【问题描述】:
我正在使用 Joi 进行 http 正文验证。我想允许 keyA 存在或 keyB 存在且需要,但不能同时存在。我没有在文档中找到我要查找的内容,而且我的架构中似乎出现了一个循环循环。
const messageSchema = Joi.object().keys({
keyA: Joi.when('keyB', { is: Joi.exist(), then: Joi.forbidden(), otherwise: Joi.string().required() }),
keyB: Joi.when('keyA', { is: Joi.exist(), then: Joi.forbidden(), otherwise: Joi.string().uri().required() }),
});
有什么想法吗?
【问题讨论】:
标签: joi