[英]How to validate a Joi object based on a field type
我有以下Joi object:
const Content = Joi
.object({
type: Joi.valid('contentType1', 'contentType2')
value: 'validate with that certain type'
})
有沒有一種方法可以根據字段類型的值來驗證字段值
通過這樣做得到它:
const Content = Joi
.object({
type: Joi.valid('contentType1', 'contentType2')
value: Joi
.when('type', {
is: 'contentType1',
then: Joi.valid('Yey')
})
.when('type', {
is: 'contentType2',
then: Joi.valid('Yow')
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.