the parameter of validator 'source' is not origin value

Author: firewithwindCreated Aug 1, 2019Updated Jul 8, 2024

I use 'validator' to define rule myself, I expect the forth parameter of validator 'source' is what I passed, but it is the deeper object of what I passed. like

javascript
const desc = {
    person1: {
        type: 'object',
        fields: {
            age: {
                validator(rule, value, callback, source, options) {
                    console.log(source);
                    if (value > source.person2.age2) {
                        return callback('need less than 0');
                    }
                    return callback();
                }
            }
        }
    }
};
const validator = new Schema(desc);
validator.validate({ person1: { age: 1, sex: 1, name: '1' }, person2: { age: 2, sex: 2, name: '2' } }, { firstFields: true });

I expect 'source' is { person1: { age: 1, sex: 1, name: '1' }, person2: { age: 2, sex: 2, name: '2' } }, but I get { age: 1, sex: 1, name: '1' }. Is there any way to control 'source' ?

Source: yiminghe/async-validator