Skip to content

Commit 813eb63

Browse files
Csaba Imre Zemplenipboettch
Csaba Imre Zempleni
authored andcommitted
Adding verbose error messages for allOf logical combination
1 parent 3a439bd commit 813eb63

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/json-validator.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class logical_combination : public schema
474474
esub.propagate(error_summary, "case#" + std::to_string(index) + "] ");
475475
}
476476

477-
if (is_validate_complete(instance, ptr, e, esub, count))
477+
if (is_validate_complete(instance, ptr, e, esub, count, index))
478478
return;
479479
}
480480

@@ -486,7 +486,7 @@ class logical_combination : public schema
486486

487487
// specialized for each of the logical_combination_types
488488
static const std::string key;
489-
static bool is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t);
489+
static bool is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t, size_t);
490490

491491
public:
492492
logical_combination(json &sch,
@@ -511,21 +511,24 @@ template <>
511511
const std::string logical_combination<oneOf>::key = "oneOf";
512512

513513
template <>
514-
bool logical_combination<allOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t)
514+
bool logical_combination<allOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t, size_t current_schema_index)
515515
{
516516
if (esub)
517+
{
517518
e.error(esub.error_entry_list_.front().ptr_, esub.error_entry_list_.front().instance_, "at least one subschema has failed, but all of them are required to validate - " + esub.error_entry_list_.front().message_);
519+
esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] ");
520+
}
518521
return esub;
519522
}
520523

521524
template <>
522-
bool logical_combination<anyOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t count)
525+
bool logical_combination<anyOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t count, size_t)
523526
{
524527
return count == 1;
525528
}
526529

527530
template <>
528-
bool logical_combination<oneOf>::is_validate_complete(const json &instance, const json::json_pointer &ptr, error_handler &e, const logical_combination_error_handler &, size_t count)
531+
bool logical_combination<oneOf>::is_validate_complete(const json &instance, const json::json_pointer &ptr, error_handler &e, const logical_combination_error_handler &, size_t count, size_t)
529532
{
530533
if (count > 1)
531534
e.error(ptr, instance, "more than one subschema has succeeded, but exactly one of them is required to validate");

0 commit comments

Comments
 (0)