-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
Hi! I encountered incorrect validation of an array of objects.
Code:
const Validator = require('fastest-validator');
const v = new Validator();
const schema = {
$$root: true,
type: 'array',
items: {
type: 'multi',
rules: [
{
type: 'object',
props: {
data: {
type: 'object',
props: { position: { type: 'number' } },
},
meta: {
type: 'object',
props: { op: { type: 'equal', value: 'up' } },
},
},
},
{
type: 'object',
props: {
data: {
type: 'object',
props: { value: { type: 'string' } },
},
meta: {
type: 'object',
props: { op: { type: 'equal', value: 'down' } },
},
},
},
],
},
};
const check = v.compile(schema);
const data = [
{
data: { position: 1 },
meta: { op: 'down' },
},
{
data: { value: 'val' },
meta: { op: 'down' },
},
];
console.log(check(data));
// Print
// [
// {
// type: 'equalValue',
// message: "The '[0].meta.op' field value must be equal to 'up'.",
// field: '[0].meta.op',
// expected: 'up',
// actual: 'down'
// },
// {
// type: 'required',
// message: "The '[0].data.value' field is required.",
// field: '[0].data.value',
// actual: undefined
// }
// ]
Is there any way to make this work?
Metadata
Metadata
Assignees
Labels
No labels