acornejo/jjv — pull request #22 by fpirsch (2014-05-15 14:28:19+00:00)
Title: Heuristics to improve "oneOf" errors reports

When no alternative match, `objerr` always contains the errors for the last alternative.
e.g. in a `oneOf["horse", "bird"]`, if one horse's coat color does not validate in the schema enum, the error report will complain that it doesn't have the required wings, beak, size, weight, and it shouldn't have hooves. Because none of the schemas match, and the last one tested is "bird".

This PR counts the errors generated by each alternative schema, and assumes the object "should have matched" the schema that generated the fewer errors. In the example above, "horse" returns 1 error but "bird" returns many more, so the "horse" schema is chosen and the "coat color" problem is correctly reported.

This problem is probably indecidable, this is just one way to deal with it. I suppose it is good enough in most cases.