是否可以验证
joi
架构没有得到转换错误?i、 我有
不
但我想验证
仅限字段。
方法如下:
const Joi = require("joi");
const _ = require('lodash');
const testSchema = Joi.object().keys({
name: Joi.string().trim().min(5).max(25).required(),
allowed: Joi.number().integer().min(0).max(1).default(0)
});
// works smoothly; no error
// const {error, value} = Joi.validate({name :"abc", allowed: 1}, testSchema);
// (Way 1) --> Error: "value" must be a number
// const {error, value} = Joi.validate({name :"abc", allowed: 1}, Joi.reach(testSchema, 'allowed'));
// (Way 2) --> Error: "value" must be a number
const {error, value} = Joi.validate({name :"abc", allowed: 1}, _.find(testSchema._inner.children, {key: 'allowed'}).schema);
console.log(error);
另外,我知道
从较小的模式合成最终模式的方法,但我不想这样做。