Merge pull request #6 from shsfre09/change_behavior_oneof_constraint_error

Push oneOf constraint error only when validation fails actually
This commit is contained in:
Tristan Penman 2015-07-06 17:35:48 +02:00
commit 600aeb97a6

View File

@ -755,14 +755,26 @@ public:
virtual bool visit(const OneOfConstraint &constraint)
{
unsigned int numValidated = 0;
ValidationResults newResults;
ValidationResults *childResults = (results) ? &newResults : NULL;
BOOST_FOREACH( const Schema &schema, constraint.schemas ) {
if (validateSchema(schema)) {
ValidationVisitor<AdapterType> v(target, context, strictTypes, childResults);
if (v.validateSchema(schema)) {
numValidated++;
}
}
if (numValidated != 1) {
if (numValidated == 0) {
if (results) {
ValidationResults::Error childError;
while (childResults->popError(childError)) {
results->pushError(childError.context, childError.description);
}
results->pushError(context, "Failed to validate against any child schemas allowed by oneOf constraint.");
}
return false;
} else if (numValidated != 1) {
if (results) {
results->pushError(context, "Failed to validate against exactly one child schema.");
}