Adding verbose error messages for allOf logical combination

This commit is contained in:
Csaba Imre Zempleni 2023-12-20 15:10:00 +01:00 committed by Patrick Boettcher
parent 3a439bdbe9
commit 813eb6312b

View File

@ -474,7 +474,7 @@ class logical_combination : public schema
esub.propagate(error_summary, "case#" + std::to_string(index) + "] "); 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; return;
} }
@ -486,7 +486,7 @@ class logical_combination : public schema
// specialized for each of the logical_combination_types // specialized for each of the logical_combination_types
static const std::string key; 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: public:
logical_combination(json &sch, logical_combination(json &sch,
@ -511,21 +511,24 @@ template <>
const std::string logical_combination<oneOf>::key = "oneOf"; const std::string logical_combination<oneOf>::key = "oneOf";
template <> 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) 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_); 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; return esub;
} }
template <> 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; return count == 1;
} }
template <> 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) if (count > 1)
e.error(ptr, instance, "more than one subschema has succeeded, but exactly one of them is required to validate"); e.error(ptr, instance, "more than one subschema has succeeded, but exactly one of them is required to validate");