繁体   English   中英

多个Joi验证类型

[英]Multiple Joi validation types

我搜索了很多,但没有发现允许在Joi进行多种类型验证

链接: https//github.com/hapijs/joi

我想用这样的东西:

validate: {
    type: joi.or([
        joi.string(),
        joi.array(),
    ])
};

尝试:

validate: {
    type: joi.alternatives().try(joi.string(), joi.array())
}

要么:

validate: {
    type: [joi.string(), joi.array()]
}

请参阅: https//github.com/hapijs/joi/blob/v10.1.0/API.md#alternatives

export const saveDeviceCommandsSchema = {
  devices: [
    Joi.array().items(Joi.string().required()).required(),
    Joi.string().valid('all').required().lowercase()
  ],
  info: Joi.array()

}; 为对象指定多于验证规则的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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