-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Currently the validation rules applied to a schema seem to be applied only once.
This means that using the same validator to validate two different objects will produce a false positive.
Example:
final validator = vine.compile(
vine.object({
'username': vine.string().minLength(3).maxLength(20),
'email': vine.string().email(),
'age': vine.number().min(18).optional(),
'isAdmin': vine.boolean(),
'features': vine.array(vine.string()),
}));
try {
final payload = {
'username': 'john Doe',
'email': 'john@example.com',
'age': 25,
'isAdmin': true,
'features': ['MANAGE'],
};
final data = validator.validate(payload);
print('Valid data: $data');
final data2 = validator.validate({
...payload,
'age': 17, // Invalid age
});
print('Valid data: $data2');
} catch (e) {
print('Validation error: $e');
}As you can see I used the same schema proposed in the README and the results are the following:
Valid data: {username: john Doe, email: john@example.com, age: 25, isAdmin: true, features: [MANAGE]}
Valid data: {username: john Doe, email: john@example.com, age: 17, isAdmin: true, features: [MANAGE]}As you can see the second iteration should've failed since it violated the min(18) rule for the age but it passed.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working