javascript - 如何在 japi joi 中进行嵌套对象验证
问题描述
使用嵌套对象验证 joi
提前谢谢如果有人可以请帮助
我试过这个但没有实现嵌套验证
var nestedSchema = Joi.array().items(Joi.object().keys({
title: Joi.string(),
type: Joi.string().valid(["postback", "web_url","nested"]).required(),
url: Joi.string(),
payload: Joi.string(),
{
locale: Joi.string(),
composerInputDisabled: Joi.boolean().valid([true, false]).required(),
call_to_actions: Joi.array().items(Joi.object().keys({
title: Joi.string(),
type: Joi.string().valid(["postback", "web_url", "nested"]).required(),
url: Joi.string(),
payload: Joi.string(),
call_to_actions: Joi.array().when('type', {
is: 'nested', then: nestedSchema
}).concat(Joi.array().when('type', {
is: 'nested', then: nestedSchema
})).concat(Joi.array().when('type', {
is: 'nested', then: nestedSchema
}))
}))
}?
解决方案
你可以看看这个页面:https ://www.npmjs.com/package/jsonschema 它认为它应该可以解决你的问题
推荐阅读
- go - 如何破解马提尼中间件
- amazon-web-services - 手动更新 AWS 凭证文件
- python - ImportError:无法从“django.shortcuts”导入名称“render_to_response”
- java - 某些操作会产生不需要的结果
- sql - SQL Server:将特定记录导出到 xml 文件
- c - 当我使用gets时,我的C程序不会停止填充向量
- constraint-programming - 使用 minisat 解决 SAT 问题
- python - 获取列表中重复次数最多的名称,或者如果有平局,则按字母顺序排列第一个
- android - 自定义视图上的双向数据绑定自定义属性
- javascript - 为什么这个“if”语句放置有效