validator: $ref to array-elements implemented
This commit is contained in:
parent
2e53f0e5db
commit
43bd5b8e7d
@ -462,11 +462,24 @@ class json_validator
|
|||||||
|
|
||||||
std::string name = match->str().substr(1);
|
std::string name = match->str().substr(1);
|
||||||
|
|
||||||
|
switch (schema->type()) {
|
||||||
|
case json::value_t::array: {
|
||||||
|
auto index = std::stoul(name);
|
||||||
|
if (index >= schema->size())
|
||||||
|
throw std::out_of_range("reference schema " + r + " is out of range for array-reference\n");
|
||||||
|
schema = &((*schema)[index]);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case json::value_t::object: {
|
||||||
const auto &sub = schema->find(name);
|
const auto &sub = schema->find(name);
|
||||||
if (sub == schema->end())
|
if (sub == schema->end())
|
||||||
throw std::invalid_argument("reference schema " + r + " not found\n");
|
throw std::invalid_argument("reference schema " + r + " not found for object\n");
|
||||||
|
|
||||||
schema = &(*sub);
|
schema = &(*sub);
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
schema_references[r] = schema;
|
schema_references[r] = schema;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user