Skip to content

Commit

Permalink
Adding verbose error messages for allOf logical combination
Browse files Browse the repository at this point in the history
  • Loading branch information
Csaba Imre Zempleni authored and pboettch committed Feb 7, 2024
1 parent 3a439bd commit 813eb63
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/json-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class logical_combination : public schema
esub.propagate(error_summary, "case#" + std::to_string(index) + "] ");
}

if (is_validate_complete(instance, ptr, e, esub, count))
if (is_validate_complete(instance, ptr, e, esub, count, index))
return;
}

Expand All @@ -486,7 +486,7 @@ class logical_combination : public schema

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

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

template <>
bool logical_combination<allOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t)
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)
{
if (esub)
{
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_);
esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] ");
}
return esub;
}

template <>
bool logical_combination<anyOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t count)
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)
{
return count == 1;
}

template <>
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)
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)
{
if (count > 1)
e.error(ptr, instance, "more than one subschema has succeeded, but exactly one of them is required to validate");
Expand Down

0 comments on commit 813eb63

Please sign in to comment.