Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望当“b”是“foo”或“bar”时需要字段“a”,否则是可选的。
我看到单个字段的文档:
a: Joi.string().when('b', { is: 'foo', then: Joi.required() })
我将如何实现上述目标?
您可以Joi.valid('bar', 'foo')用作 的值is:
Joi.valid('bar', 'foo')
is
a: Joi.string().when('b', { is: Joi.valid('bar', 'foo'), then: Joi.required() })