diff --git a/json/schema.cpp b/json/schema.cpp index b8daa621..061640f6 100644 --- a/json/schema.cpp +++ b/json/schema.cpp @@ -18,7 +18,9 @@ #include "./tree.hpp" #include "./except.hpp" + #include "../debug.hpp" +#include "../io.hpp" #include "../maths.hpp" #include @@ -443,3 +445,14 @@ json::schema::validate (json::tree::node &data, return ::validate (data, schema.as_object ()); } + + +//----------------------------------------------------------------------------- +void +json::schema::validate (json::tree::node &data, + const boost::filesystem::path &schema_path) +{ + const util::mapped_file schema_data (schema_path.string ().c_str ()); + auto schema_object = json::tree::parse (schema_data.as_view ()); + validate (data, schema_object->as_object ()); +} diff --git a/json/schema.hpp b/json/schema.hpp index bc263322..a1f5af6d 100644 --- a/json/schema.hpp +++ b/json/schema.hpp @@ -20,11 +20,16 @@ #include "./fwd.hpp" #include +#include namespace json { namespace schema { - void - validate (json::tree::node &data, - const json::tree::object &schema); + // Validate the json tree using the provide schema object or path. + // + // Note that the data object being validated may be altered in the process + // of validation. If a value is not present but the schema specifies a + // default, it will be realised in the data object. + void validate (json::tree::node &data, const json::tree::object &schema); + void validate (json::tree::node &data, const boost::filesystem::path &schema); } } #endif