Skip to content

Commit 7cbb217

Browse files
fixed multiple type matching behaviour
1 parent b901236 commit 7cbb217

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/sjv/sjv.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ namespace sjv
8080

8181
bool SJV::verify_json(const string &pointer, const json &input, const json &rules)
8282
{
83+
// if (pointer == "/geometry/*/surface_selection/*")
84+
// std::cout << "gotcha" << std::endl;
8385
// Find all rules that apply for the input node
8486
// TODO: accelerate this
8587
std::vector<json> matching_rules = collect_pointer(pointer, rules);
@@ -97,10 +99,16 @@ namespace sjv
9799

98100
// Test all rules, only one must pass, otherwise throw exception
99101
int count = 0;
102+
json single_matched_rule;
100103

101104
for (auto i : matching_rules)
105+
{
102106
if (verify_rule(input, i))
107+
{
103108
count++;
109+
single_matched_rule = i;
110+
}
111+
}
104112

105113
if (count == 0 && !matching_rules.empty())
106114
{
@@ -141,7 +149,7 @@ namespace sjv
141149
json defaults = collect_default_rules(new_pointer, rules);
142150

143151
// if it is mandatory, make sure there are no defaults
144-
if (matching_rules[0].contains("required") && contained_in_list(i.key(), matching_rules[0]["required"]))
152+
if (single_matched_rule.contains("required") && contained_in_list(i.key(), single_matched_rule["required"]))
145153
{
146154
if (defaults.size() != 0)
147155
{
@@ -150,7 +158,7 @@ namespace sjv
150158
}
151159
}
152160
// if it is optional, there should be only one default in the specs
153-
else if (matching_rules[0].contains("optional") && contained_in_list(i.key(), matching_rules[0]["optional"]))
161+
else if (single_matched_rule.contains("optional") && contained_in_list(i.key(), single_matched_rule["optional"]))
154162
{
155163
if (defaults.size() != 1)
156164
{

tests/test_validator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ TEST_CASE("pushbox", "[validator]")
252252

253253
bool r = sjv.verify_json(input,rules);
254254
std:: string s = sjv.log2str();
255-
WARN(s);
255+
INFO(s);
256256
REQUIRE(r);
257257
}
258258

@@ -270,7 +270,7 @@ TEST_CASE("screw", "[validator]")
270270

271271
bool r = sjv.verify_json(input,rules);
272272
std:: string s = sjv.log2str();
273-
WARN(s);
273+
INFO(s);
274274
REQUIRE(r);
275275
}
276276

@@ -288,7 +288,7 @@ TEST_CASE("slingshot", "[validator]")
288288

289289
bool r = sjv.verify_json(input,rules);
290290
std:: string s = sjv.log2str();
291-
WARN(s);
291+
INFO(s);
292292
REQUIRE(r);
293293
}
294294

0 commit comments

Comments
 (0)