Implement JSON schema and validation
What
Right now we don't have any well defined schema for any of the various JSON files that are used as input to various places in YARR. This can lead to issues (e.g. erroneously missing/misspelled registers for FrontEnd configs, incomplete scan configurations, etc...) and also to ill-defined requirements (e.g. does the FrontEnd config provide the minimum set of requirements necessary for this FrontEnd object?).
Potential C++ Solution
Use something like json-schema-validator to run a validation step on passed in JSON objects.
JSON schemas can be parsed via any language which supports JSON (all of them). The JSON schema spec is defined here.
The Way It Works in C++
You define a (set of) JSON schema(s) and then do:
using nlohmann::json_schema::json_validator;
...
json config_to_validate;
json_validator validator;
std::string schema_filepath = ...;
valdiator.set_root_schema(json::parse(schema_filepath));
try {
validator.validate(config_to_validate);
} catch(std::exception& e) {
std::cout << "Whoops! Config fails schema validation check with error: " << e.what() << std::endl;
}
Potential Issue
Generally, the default is to use variant
instead of nlohmann::json
. I have't checked if the schema validation will work against variant
objects, and do not know if that would pose any issue -- at least at the usual runtime.
In any case,
- In CI, a JSON validation stage can be added and the YARR libs can be compiled against
nlohmann::json
in this stage - The schema is independent of the JSON implementation, so depending on where the validation is run the
variant
vsnlohmann::json
issue might not arise. For example, running the JSON validation stage from within a higher-level python interface prior to execution of scans (which potentially link againstvariant
). From the python stage, there would be no need to link against a C++ library for the JSON validation that depends onnlohmann::json
, since there is already thejsonschema
module.