【问题标题】:Joi validation - How to validate an array of objects where only one object is required and the other is notJoi 验证 - 如何验证只需要一个对象而不需要另一个对象的对象数组
【发布时间】:2019-10-01 08:24:18
【问题描述】:

我想使用 Joi 验证一个包含多个对象的数组。虽然我找不到将数组列表中的一个对象标记为“required = false”的方法。

有没有办法用 Joi 完成这个?

【问题讨论】:

  • 在需要的对象上使用 .required(true),另一个默认是可选的。
  • 能否详细介绍一下您的数据,您有哪些元素数组?

标签: node.js validation hapijs joi


【解决方案1】:

试试这个方法

Joi.array().items(Joi.object({
   // Object schema
}))

Ref link 1

Ref link 2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2022-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多