Ajout du validateur json + correctif factory metadata
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
|
||||
add_executable(issue-93 issue-93.cpp)
|
||||
target_link_libraries(issue-93 nlohmann_json_schema_validator)
|
||||
|
||||
add_test(NAME issue-93
|
||||
COMMAND issue-93
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"type":"array",
|
||||
"items": {
|
||||
"type":"object",
|
||||
"properties": {
|
||||
"renderable": {
|
||||
"$ref":"/components.schema.json#/Renderable"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"Renderable": {
|
||||
"type":"object",
|
||||
"properties": {
|
||||
"fg":{
|
||||
"$ref":"/types/color.schema.json"
|
||||
},
|
||||
"bg":{
|
||||
"$ref":"/types/color.schema.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
lib/All/json-schema-validator/test/issue-93/issue-93.cpp
Normal file
55
lib/All/json-schema-validator/test/issue-93/issue-93.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using nlohmann::json;
|
||||
using nlohmann::json_uri;
|
||||
using nlohmann::json_schema::json_validator;
|
||||
|
||||
static const auto expected_patch = R"(
|
||||
[{"op":"add","path":"/0/renderable/bg","value":"Black"}]
|
||||
)"_json;
|
||||
|
||||
static const auto instance = R"(
|
||||
[
|
||||
{
|
||||
"name":"player",
|
||||
"renderable": {
|
||||
"fg":"White"
|
||||
}
|
||||
}
|
||||
]
|
||||
)"_json;
|
||||
|
||||
static void loader(const json_uri &uri, json &schema)
|
||||
{
|
||||
std::string filename = "./" + uri.path();
|
||||
std::ifstream lf(filename);
|
||||
if (!lf.good())
|
||||
throw std::invalid_argument("could not open " + uri.url() + " tried with " + filename);
|
||||
try {
|
||||
lf >> schema;
|
||||
} catch (const std::exception &e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
json_validator validator(loader);
|
||||
|
||||
std::fstream f("blueprints.schema.json");
|
||||
|
||||
json schema;
|
||||
f >> schema;
|
||||
|
||||
validator.set_root_schema(schema);
|
||||
|
||||
auto missing_default_patch = validator.validate(instance);
|
||||
|
||||
std::cerr << missing_default_patch << "\n";
|
||||
std::cerr << expected_patch << "\n";
|
||||
|
||||
return missing_default_patch != expected_patch;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"type":"string",
|
||||
"default":"Black"
|
||||
}
|
||||
Reference in New Issue
Block a user