fix #75: unknown keywords may contain sub-schemas
Now when an unknown keyword appears and its value is an object, sub-unknown-keywords are inserted as possible sub-schemas.
This commit is contained in:
parent
e2bdcbea2d
commit
49131a8713
@ -130,7 +130,7 @@ public:
|
||||
{
|
||||
auto &file = get_or_create_file(uri.location());
|
||||
auto new_uri = uri.append(key);
|
||||
auto fragment = new_uri.fragment();
|
||||
auto fragment = new_uri.pointer();
|
||||
|
||||
// is there a reference looking for this unknown-keyword, which is thus no longer a unknown keyword but a schema
|
||||
auto unresolved = file.unresolved.find(fragment);
|
||||
@ -138,6 +138,11 @@ public:
|
||||
schema::make(value, this, {}, {{new_uri}});
|
||||
else // no, nothing ref'd it, keep for later
|
||||
file.unknown_keywords[fragment] = value;
|
||||
|
||||
// recursively add possible subschemas of unknown keywords
|
||||
if (value.type() == json::value_t::object)
|
||||
for (auto &subsch : value.items())
|
||||
insert_unknown_keyword(new_uri, subsch.key(), subsch.value());
|
||||
}
|
||||
|
||||
std::shared_ptr<schema> get_or_create_ref(const json_uri &uri)
|
||||
@ -151,7 +156,7 @@ public:
|
||||
|
||||
// referencing an unknown keyword, turn it into schema
|
||||
try {
|
||||
auto &subschema = file.unknown_keywords.at(uri.fragment());
|
||||
auto &subschema = file.unknown_keywords.at(uri.pointer());
|
||||
auto s = schema::make(subschema, this, {}, {{uri}});
|
||||
file.unknown_keywords.erase(uri.fragment());
|
||||
return s;
|
||||
|
||||
3
test/issue-75/CMakeLists.txt
Normal file
3
test/issue-75/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_test_simple_schema(Issue::75
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/schema.json
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/instance.json)
|
||||
10
test/issue-75/TypeId.json
Normal file
10
test/issue-75/TypeId.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"data" : {
|
||||
"TypeId" : {
|
||||
"type" : "string",
|
||||
"description" : "POD type of data matching bmf::data::TypeId enum",
|
||||
"enum" : [ "CHAR", "UCHAR", "SHORT", "USHORT", "INT", "UINT",
|
||||
"LONG", "ULONG", "FLOAT", "DOUBLE" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
1
test/issue-75/instance.json
Normal file
1
test/issue-75/instance.json
Normal file
@ -0,0 +1 @@
|
||||
["INT", "LONG"]
|
||||
6
test/issue-75/schema.json
Normal file
6
test/issue-75/schema.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"type" : "array",
|
||||
"items": {
|
||||
"$ref": "TypeId.json#/data/TypeId"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user