gpt4 book ai didi

javascript - 多种 Joi 验证类型

转载 作者:搜寻专家 更新时间:2023-10-31 23:32:30 24 4
gpt4 key购买 nike

我搜索了很多,但没有找到允许在 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

关于javascript - 多种 Joi 验证类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41468779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com