繁体   English   中英

如何根据字段类型验证 Joi object

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM