json/schema: add path based validate
This commit is contained in:
parent
73c30561af
commit
b1bc2a816d
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
#include "./tree.hpp"
|
#include "./tree.hpp"
|
||||||
#include "./except.hpp"
|
#include "./except.hpp"
|
||||||
|
|
||||||
#include "../debug.hpp"
|
#include "../debug.hpp"
|
||||||
|
#include "../io.hpp"
|
||||||
#include "../maths.hpp"
|
#include "../maths.hpp"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
@ -443,3 +445,14 @@ json::schema::validate (json::tree::node &data,
|
|||||||
|
|
||||||
return ::validate (data, schema.as_object ());
|
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<char> ());
|
||||||
|
validate (data, schema_object->as_object ());
|
||||||
|
}
|
||||||
|
@ -20,11 +20,16 @@
|
|||||||
#include "./fwd.hpp"
|
#include "./fwd.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
namespace json { namespace schema {
|
namespace json { namespace schema {
|
||||||
void
|
// Validate the json tree using the provide schema object or path.
|
||||||
validate (json::tree::node &data,
|
//
|
||||||
const json::tree::object &schema);
|
// 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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user