fix #100: only look for "unknown keyword" if the uri contains a pointer.

This commit is contained in:
Patrick Boettcher 2020-04-09 15:34:38 +02:00 committed by Patrick Boettcher
parent 81eba4928d
commit 03af1b5e1e
4 changed files with 37 additions and 7 deletions

View File

@ -177,6 +177,10 @@ public:
return schema->second;
// referencing an unknown keyword, turn it into schema
//
// an unknown keyword can only be referenced by a json-pointer,
// not by a plain name fragment
if (uri.pointer() != "") {
try {
auto &subschema = file.unknown_keywords.at(uri.pointer()); // null is returned if not existing
auto s = schema::make(subschema, this, {}, {{uri}}); // A JSON Schema MUST be an object or a boolean.
@ -186,6 +190,7 @@ public:
}
} catch (nlohmann::detail::out_of_range &) { // at() did not find it
}
}
// get or create a schema_ref
auto r = file.unresolved.lower_bound(uri.fragment());

View File

@ -0,0 +1,6 @@
add_test_simple_schema(Issue::100
${CMAKE_CURRENT_SOURCE_DIR}/schema.json
${CMAKE_CURRENT_SOURCE_DIR}/instance.json)
set_tests_properties(Issue::100
PROPERTIES
WILL_FAIL 1)

View File

@ -0,0 +1,4 @@
{
"Prop1": 1,
"Prop2": []
}

View File

@ -0,0 +1,15 @@
{
"$id": "http://xxx.local/schemas/mySchema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"Prop1": {
"type": "integer",
"$comment": "Just a comment"
},
"Prop2": {
"$ref": "#random_ref"
}
}
}