Skip to content

Commit 66efaf9

Browse files
committed
Added expected values to enum and const error messages
1 parent 813eb63 commit 66efaf9

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/json-validator.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -429,26 +429,25 @@ enum logical_combination_types {
429429
class logical_combination_error_handler : public error_handler
430430
{
431431
public:
432-
struct error_entry
433-
{
432+
struct error_entry {
434433
json::json_pointer ptr_;
435434
json instance_;
436435
std::string message_;
437436
};
438437

439438
std::vector<error_entry> error_entry_list_;
440-
439+
441440
void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override
442441
{
443-
error_entry_list_.push_back(error_entry{ ptr, instance, message });
442+
error_entry_list_.push_back(error_entry{ptr, instance, message});
444443
}
445444

446-
void propagate(error_handler& e, const std::string& prefix) const
445+
void propagate(error_handler &e, const std::string &prefix) const
447446
{
448-
for (const error_entry& entry : error_entry_list_)
447+
for (const error_entry &entry : error_entry_list_)
449448
e.error(entry.ptr_, entry.instance_, prefix + entry.message_);
450449
}
451-
450+
452451
operator bool() const { return !error_entry_list_.empty(); }
453452
};
454453

@@ -463,7 +462,7 @@ class logical_combination : public schema
463462
logical_combination_error_handler error_summary;
464463

465464
for (std::size_t index = 0; index < subschemata_.size(); ++index) {
466-
const std::shared_ptr<schema>& s = subschemata_[index];
465+
const std::shared_ptr<schema> &s = subschemata_[index];
467466
logical_combination_error_handler esub;
468467
auto oldPatchSize = patch.get_json().size();
469468
s->validate(ptr, instance, patch, esub);
@@ -513,8 +512,7 @@ const std::string logical_combination<oneOf>::key = "oneOf";
513512
template <>
514513
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)
515514
{
516-
if (esub)
517-
{
515+
if (esub) {
518516
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_);
519517
esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] ");
520518
}
@@ -568,12 +566,12 @@ class type_schema : public schema
568566
}
569567

570568
if (!seen_in_enum)
571-
e.error(ptr, instance, "instance not found in required enum");
569+
e.error(ptr, instance, "instance not found in required enum " + enum_.second.dump());
572570
}
573571

574572
if (const_.first &&
575573
const_.second != instance)
576-
e.error(ptr, instance, "instance not const");
574+
e.error(ptr, instance, "instance not const value '" + const_.second.dump() + "'");
577575

578576
for (auto l : logic_)
579577
l->validate(ptr, instance, patch, e);

0 commit comments

Comments
 (0)