Skip to content

Commit 72c7c74

Browse files
Merge branch 'main' of github.com:geometryprocessing/json-spec-engine into main
2 parents 7612f85 + 571a02d commit 72c7c74

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/jse/jse.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace jse
1818
return verify_json("/", input_copy, rules);
1919
};
2020

21-
2221
json JSE::inject_defaults(const json &input, const json &rules)
2322
{
2423
log.clear();
@@ -27,7 +26,7 @@ namespace jse
2726
assert(b); // Make sure the original file is valid
2827

2928
// Check that the new file, after adding defaults, is also valid
30-
//assert(verify_json(input_copy, rules));
29+
// assert(verify_json(input_copy, rules));
3130

3231
return input_copy;
3332
};
@@ -147,13 +146,13 @@ namespace jse
147146
}
148147

149148
// If the dictionary is valid and has optional fields, add defaults for the optional fields
150-
151-
if (input.is_object() || input.is_null()) // Note: null fields might be objects, and thus might have optional fields
149+
150+
if (input.is_object() || input.is_null()) // Note: null fields might be objects, and thus might have optional fields
152151
if (single_matched_rule.contains("optional")) // the object has a list of optional
153152
{
154153
// std::cout << "Before adding: " << input << std::endl;
155154
for (auto &i : single_matched_rule["optional"]) // for each optional field
156-
if (!input.contains(i)) // if not already in the object
155+
if (!input.contains(i)) // if not already in the object
157156
{
158157
string new_pointer = (pointer == "/" ? "" : pointer) + "/" + string(i);
159158
json defaults = collect_default_rules(new_pointer, rules); // Find the default
@@ -162,12 +161,14 @@ namespace jse
162161
log.push_back(log_item("error", "Inconsistent specifications: " + new_pointer + " is an optional field with " + std::to_string(defaults.size()) + " default values."));
163162
return false;
164163
}
165-
input[string(i)] = defaults[0]["default"];
166-
167-
// Let's validate/inject the default subtree
168-
if (!verify_json(new_pointer, input[string(i)], rules))
169-
return false;
164+
if (defaults[0]["default"] != "skip")
165+
{
166+
input[string(i)] = defaults[0]["default"];
170167

168+
// Let's validate/inject the default subtree
169+
if (!verify_json(new_pointer, input[string(i)], rules))
170+
return false;
171+
}
171172
}
172173
// std::cout << "After adding: " << input << std::endl;
173174
}
@@ -176,7 +177,7 @@ namespace jse
176177
// All the elements in the list must pass the test
177178
if (input.is_array())
178179
{
179-
for (auto& i : input)
180+
for (auto &i : input)
180181
if (!verify_json((pointer == "/" ? "" : pointer) + "/*", i, rules))
181182
return false;
182183
}
@@ -317,6 +318,10 @@ namespace jse
317318
if (!input.contains(string(e)))
318319
return false;
319320

321+
if (rule.contains("type_name"))
322+
if (!input.contains("type") || input["type"] != rule["type_name"])
323+
return false;
324+
320325
return true;
321326
};
322327
bool JSE::verify_rule_bool(const json &input, const json &rule)

0 commit comments

Comments
 (0)