tdegrunt/jsonschema — pull request #92 by jkryl (2014-11-12 11:55:51+00:00)
Title: Display errors from oneOf, anyOf, allOf subschema validations

When oneOf, anyOf, allOf are validated the error messages are mostly useless for finding the root cause of the problem. Invalid data usually results in following message:
```
request is not exactly one from [object Object],[object Object]
```
no idea what could be wrong (especially if object definitions are complex). I have enhanced jsonschema to keep track of so-called sub-errors (errors encountered when trying to validate data against members of anyOf,oneOf,allOf array members) and display them in error messages. Here is a sample of the new output:

```
0: instance is not any of {"type":"null"},{"anyOf":[{"type":"object","properties":{"attr1":{"required":true,"type":"string"},"attr":{"required":true,"type":"number"}}},{"type":"string"}]}
0.schema[0].0: instance is not of a type(s) null
0.schema[1].0: instance is not any of {"type":"object","properties":{"attr1":{"required":true,"type":"string"},"attr":{"required":true,"type":"number"}}},{"type":"string"}
0.schema[1].0.schema[0].0: instance.attr1 is not of a type(s) string
0.schema[1].0.schema[0].1: instance.attr is required
0.schema[1].0.schema[1].0: instance is not of a type(s) string
```

While the ouput isn't easy to read, it gives you actually all information you need to localize the problem. Just for the record following schema and data were used for generating the message above:

```
js = require('jsonschema');
schema = { anyOf: [{type: 'null'}, {anyOf: [{type: 'object', properties: { attr1: { required: true, type: 'string' }, attr: { required: true, type: 'number'}}}, {type: 'string'}]}] };
var res = js.validate({attr1: 3}, schema);
console.log(res.toString());
```