jjv icon indicating copy to clipboard operation
jjv copied to clipboard

"dependencies" keyword prevents errors

Open ozum opened this issue 10 years ago • 0 comments

If there is an error in dependencies, normal errors do not appear in errors object. See example below:

var schema = {
    "type": "object",

    "properties": {
        "name": { "type": "string" },
        "surname": { "type": "string" },
        "credit_card": { "type": "number" }
    },
    "dependencies": {
        "credit_card": {
            "properties": {
                "billing_address": { "type": "string" }
            },
            "required": ["billing_address"]
        }
    },
    "required": ["name", "surname"]
};

var data = {
    "credit_card": "jj"
};

var errors  = validator.validate(schema, data);

The errors object produced is:

{
    "validation": {
        "billing_address": {
            "required": true
        }
    }
}

However errors object should report name, surname fields should be required, and credit card field should be numeric.

Same schema produces with data below.

var data = {
    "age": 28
}

{
    "validation": {
        "name": {
            "required": true
        },
        "surname": {
            "required": true
        }
    }
}

Not to clutter here, I didn't include custom checks. Custom checks have same issue.

Regards,

ozum avatar Jan 10 '15 08:01 ozum