JVal
JVal copied to clipboard
Absolute schema URI is required even for local references
Absolute schema URI is required to validate the following schema. Bug or feature?
{
"type": "object",
"properties": {
"label": {"type": "string"},
"children": {
"type": "array",
"items": {"$ref": "#"}
}
},
"required": ["label"]
}
Not a bug per se, more an annoying limitation. Resolution of relative URIs currently requires an absolute base url no matter what. However, if it cannot be avoided for most relative URIs, an exception could probably be made for pointers/fragments, which are relative but point to the same document.
Assuming we make Resolver::registerSchema public, it would be nice support not-requiring absolute URLs everytime the target schema is known and therefore does not require fetching.
$validator = Validator::buildDefault();
$validator->getResolver()->registerSchema($commonSchema, new Uri('shared-definitions.json'));
$validator->validate($instance, json_decode('
{
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"$ref": "shared-definitions.json#age"}
},
"required": ["label"]
}
'));