-
-
Notifications
You must be signed in to change notification settings - Fork 190
Closed
Description
Describe the bug
There is a bug in class additional_properties_validator which terminates the loop over the instances after the first item even when the reporter function returns walk_result::advance
| break; |
Enumerate the steps to reproduce the bug
This test fails since the size of the result size is 1, not 2
TEST(JsonconsTests, SchemaReporter_MultipleAdditionalValues)
{
std::vector<jsoncons::jsonschema::validation_message> result;
auto reporter =
[&result](const jsoncons::jsonschema::validation_message& message) -> jsoncons::jsonschema::walk_result
{
std::cout << "+++++++++++++++++" << std::endl;
std::cout << "message: " << message.message() << std::endl;
std::cout << "instance location: " << message.instance_location().string() << std::endl;
std::cout << "schema location: " << message.schema_location().string() << std::endl;
std::cout << "keyword: " << message.keyword() << std::endl;
std::cout << "evaluation path: " << message.eval_path().string() << std::endl;
std::cout << "+++++++++++++++++" << std::endl;
std::cout << std::endl;
result.push_back(message);
return jsoncons::jsonschema::walk_result::advance;
};
std::string schemaString = R"(
{
"$schema" : "https://json-schema.org/draft/2020-12/schema",
"type" : "object",
"additionalProperties" : false,
"required" : [ "s1" ],
"properties" : {
"s1" : {"type" : "string"},
"n2" : {"type" : "integer"}
}
}
)";
std::string dataString = R"(
{
"s1": "1",
"n2": 2,
"x4": 4,
"x5": 5
}
)";
auto schema = jsoncons::jsonschema::make_json_schema(jsoncons::json::parse(schemaString));
auto parsed = jsoncons::json::parse(dataString);
schema.validate(parsed, reporter);
ASSERT_EQ(2U, result.size());
EXPECT_EQ("additionalProperties"s, result[0].keyword());
EXPECT_EQ("/additionalProperties/x4"s, result[0].eval_path().string());
EXPECT_EQ("/x4"s, result[0].instance_location().string());
EXPECT_EQ("additionalProperties"s, result[1].keyword());
EXPECT_EQ("/additionalProperties/x5"s, result[1].eval_path().string());
EXPECT_EQ("/x5"s, result[1].instance_location().string());
}
Include a small, self-contained example if possible
What compiler, architecture, and operating system?
Visual Studio 2022 on Windows 11,
Toolset: Visual Studio 2022 (v143),
C++ Language Standard: Preview - ISO C++23 Standard (/std:c++23preview)
What jsoncons library version?
- Latest release 1.4.3
- master