[英]Joi Validator must valid at least given value, but other will also allowed
[英]Require valid string in Joi which must be in other propertie's array
我想用Joi架构解决以下问题:
有属性locales
(arra)和属性default_locale
(string),后者必须在locales
数组中。
我怎么能做到这一点? 到目前为止,我有以下内容:
Joi.object().keys({
locales:
Joi.array()
.items(
Joi.string()
.valid(AllLocales)) // must be any of available locales
.required(),
default_locale: // this should be any of the values from locales
Joi.string()
.required()
});
我发现我可以简单地使用ref
( https://github.com/hapijs/joi/blob/v14.3.1/API.md#refkey-options )。
default_locale: Joi.string().valid(Joi.ref('locales')).required()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.