fix #101: throw an exception if JSON-type of schema is not one of the expected types

This commit is contained in:
Patrick Boettcher 2020-04-09 15:50:25 +02:00
parent 81eba4928d
commit c6d94ab30c
4 changed files with 20 additions and 1 deletions

View File

@ -1158,7 +1158,7 @@ std::shared_ptr<schema> schema::make(json &schema,
schema.erase("title"); schema.erase("title");
schema.erase("description"); schema.erase("description");
} else { } else {
return nullptr; // TODO error/throw? when schema is invalid throw std::invalid_argument("invalid JSON-type for a schema for " + uris[0].to_string() + ", expected: boolean or object");
} }
for (auto &uri : uris) { // for all URIs this schema is referenced by for (auto &uri : uris) { // for all URIs this schema is referenced by

View File

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

View File

@ -0,0 +1 @@
{"top": 1}

View File

@ -0,0 +1,12 @@
{
"$id": "http://xxx.local/schemas/mySchema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"top": {
"type": "integer"
},
"required": ["top"]
}
}