Closed jmauerhan closed 3 years ago
Thank you for filing this issue.
The issue happens when schema is imported from a file (or URI).
Such code would fail with an exception.
$schemaData = json_decode('{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Parent",
"type": "object",
"required": [
"title",
"child"
],
"properties": {
"title": {
"type": "string"
},
"second_prop": {
"type": "uri"
},
"child": {
"type": "object",
"required": [
"title"
],
"properties": {
"title": {
"type": "string"
}
}
}
}
}');
Schema::import($schemaData); // Fails with exception.
But this code would not fail with an exception.
Schema::import($pathToSchemaFile); // Same schema in file.
It is caused by an error-tolerant mode while dereferencing schemas.
When my schema contains some invalid property definition, the validation works up until that point, then stops validating. This is confusing because if one property is defined incorrectly, there is no indication of the actual problem, and makes it appear as if an invalid JSON instance actually validates, when the problem is really in the schema.
Given this simple schema:
When using the
Schema::in
functionality, the validation works. This example throws an exception, as I expected:$schema = Schema::import('schema/example.schema.json'); $schema->in($data);
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Parent", "type": "object", "required": [ "title", "child" ], "properties": { "title": { "type": "string" }, "second_prop": { "type": "uri" }, "child": { "type": "object", "required": [ "title" ], "properties": { "title": { "type": "string" } } } } }
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Parent", "type": "object", "required": [ "title", "child" ], "properties": { "title": { "type": "string" }, "second_prop": { "type": "string", "format":"uri" }, "child": { "type": "object", "required": [ "title" ], "properties": { "title": { "type": "string" } } } } }