acornejo/jjv — pull request #25 by silas (2014-06-14 06:23:25+00:00)
Title: Allow user to override checkValidity

What do you think about letting the user override checkValidity?

``` javascript
var env = jjv();

var checkValidity = env.checkValidity;

env.checkValidity = function(env, schema_stack, object_stack, options) {
var result = checkValidity(env, schema_stack, object_stack, options);
// do something interesting
return result;
};

env.validate(schema, data);
```

This would make it a lot easier to write error formatting code. Right now I have to re-walk the JSON schema (along with the data object) if I want to get access to stuff like enum lists (and the invalid data).

Also, the current validation object doesn't give you enough information re-walk the JSON schema where the path includes stuff like anyOf (without re-validating the data).

Just for reference, I'm trying to get errors like the following:

``` json
{
"code": "VALIDATION_ENUM_MISMATCH",
"message": "Not a valid option "three", expects: one, two",
"data": "three",
"path": "$.str"
}
``

For something like

```
var schema = {
type: 'object',
properties: {
str: { type: 'string', enum: ['one', 'two'] },
}
};

var data = {
str: 'three',
};
```