You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I use this code (inline scheme)...
`$jsonSchema = <<<'JSON'
{
"type": "object",
"properties": {
"CodigoEmpresa": { "type": "string"},
"Localidade": {"type": "string"}
}
},
"required": ["CodigoEmpresa","Localidade"],
}
JSON;
$jsonSchemaObject = json_decode($jsonSchema);
$schemaStorage = new SchemaStorage();
$schemaStorage->addSchema('file://mySchema', $jsonSchemaObject);
$jsonValidator = new Validator(new Factory($schemaStorage));
// JSON must be decoded before it can be validated
$jsonToValidateObject = json_decode('{"data":123}');
// Do validation (use isValid() and getErrors() to check the result)
$jsonValidator->validate($jsonToValidateObject, $jsonSchemaObject);
if ($jsonValidator->isValid()) {
echo "The supplied JSON validates against the schema.\n";
} else {
echo "JSON does not validate. Violations:\n";
foreach ($jsonValidator->getErrors() as $error) {
printf("[%s] %s\n", $error['property'], $error['message']);
}
}
die();`
But i have this error...
JsonSchema\Exception\ResourceNotFoundException
file_get_contents(file://mySchema): failed to open stream: no suitable wrapper could be found
What is wrong?
thanks!
The text was updated successfully, but these errors were encountered:
@msarocha you're lading the schema with a file:// prefix but are providing an inline schema. This is why your code is throwing an exception while trying to call file_get_contents().
The fixed code (including some boiler plate to run it from the library root and a fix of the schema to be valid JSON) is shown below. In an attempt to cleanup this repo we are trying to filter the issues and see which ones might be closed. Is it safe to assume with this answer it can be closed? Feel free to close it yourself with some comments if helpful.
Hi!
I use this code (inline scheme)...
`$jsonSchema = <<<'JSON'
{
"type": "object",
"properties": {
"CodigoEmpresa": { "type": "string"},
"Localidade": {"type": "string"}
}
},
"required": ["CodigoEmpresa","Localidade"],
}
JSON;
But i have this error...
JsonSchema\Exception\ResourceNotFoundException
file_get_contents(file://mySchema): failed to open stream: no suitable wrapper could be found
What is wrong?
thanks!
The text was updated successfully, but these errors were encountered: