Joi在可选字段上需要错误消息

时间:2020-10-28 11:55:51

标签: javascript joi

我有一个端点,用户可以在其中查询:

$scope.$$destroyed

/url/data?timestamp=1603885733790

以下架构正确验证了此行为:

/url/data?start=1603885730000&end=1603885733790

但是,首选选项是用户按时间戳提交请求。因此,当用户举起Joi.object({ start: Joi.when('timestamp', { not: Joi.exist(), then: Joi.date().required(), }), end: Joi.when('timestamp', { not: Joi.exist(), then: Joi.date().required(), }) timestamp: Joi.date() }) 之类的无效请求时,我希望返回消息/url/data。相反,我得到了:

timestamp is required

0 个答案:

没有答案
相关问题