首页 > 解决方案 > 如何在 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
                    }))
                }))
            }?

标签: javascripttypescripthapijsjoi

解决方案


你可以看看这个页面:https ://www.npmjs.com/package/jsonschema 它认为它应该可以解决你的问题


推荐阅读