4#include <nlohmann/json-schema.hpp>
5#include <nlohmann/json.hpp>
12 std::cerr << "Failed: '" << a << "' != '" << b << "'\n";
17#define EXPECT_THROW(foo)
22 } catch (std::exception &) {
35{
36 "type": "object",
37 "properties": {
38 "standard_string": {
39 "type": "string"
40 },
41 "binary_data": {
42 "type": "string",
43 "contentEncoding": "binary"
44 }
45 },
46 "additionalProperties": false
47}
48)");
51{
52 "type": "object",
53 "properties": {
54 "something": {
55 "type": ["string", "number", "boolean"],
56 "contentEncoding": "binary"
57 }
58 }
59}
60)");
63{
64 "type": "object",
65 "properties": {
66 "something": {
67 "type": ["string", "number", "boolean"]
68 }
69 }
70}
71)");
75 void error(
const nlohmann::json::json_pointer &ptr,
const json &,
const std::string &message)
override
78 std::cerr <<
"ERROR: '" << ptr <<
"' - '"
80 <<
"': " << message <<
"\n";
94static void content(
const std::string &contentEncoding,
const std::string &contentMediaType,
const json &instance)
96 std::cerr <<
"mediaType: '" << contentMediaType <<
"', encoding: '" << contentEncoding <<
"'\n";
98 if (contentEncoding ==
"binary") {
99 if (instance.type() !=
json::value_t::binary) {
100 throw std::invalid_argument{
"expected binary data"};
103 if (instance.type() ==
json::value_t::binary) {
104 throw std::invalid_argument{
"expected string, but get binary"};
115 std::string as_binary =
"hello world";
116 std::copy(as_binary.begin(), as_binary.end(), std::back_inserter(arr));
126 val
.validate({{
"standard_string",
"some string"}, {
"binary_data", binary}}
, err
);
131 val
.validate({{
"binary_data",
"string, but expect binary data"}}
, err
);
137 val
.validate({{
"standard_string", binary}, {
"binary_data", binary}}
, err
);
const json array_of_types
const json array_of_types_without_binary
nlohmann::json_schema::json_validator validator
#define EXPECT_THROW(foo)
static void content(const std::string &contentEncoding, const std::string &contentMediaType, const json &instance)
void error(const json::json_pointer &, const json &, const std::string &) override
void set_root_schema(const json &)
json_validator(schema_loader=nullptr, format_checker=nullptr, content_checker=nullptr)
json validate(const json &, error_handler &, const json_uri &initial_uri=json_uri("#")) const
void error(const nlohmann::json::json_pointer &ptr, const json &, const std::string &message) override
std::vector< nlohmann::json::json_pointer > failed_pointers