-
Notifications
You must be signed in to change notification settings - Fork 356
Silence error #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you provide some example data? |
Hi, I have not kept: I tested "json-schema" at work, but I used another solution to validate the json. Memory, nothing happens when I call the method "check" with tables instead of stdclass. When I say "nothing happens", I mean that no exception is thrown, the getErrors () method returns an empty array. I think it's "dangerous", I usually test with fake, so I knew it was not normal. Aside from that, once past a stdclass, I managed to validate my json, it seems to work well :) Thank you! I "star"! |
Quick example: This should be invalid as the input vars are incorrectly formatted, i.e. missing json_decode(). However, it validates! <?php
require_once 'vendor/autoload.php';
// Validate ...
$_Input = '
{
"id": 1,
"tags": ["home", "green"]
}
';
$_Schema = '
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acmes catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string",
"required": true
}
}
}
';
$validator = new \JsonSchema\Validator();
$validator->check($_Input, $_Schema);
if (!$validator->isValid()) {
foreach ($validator->getErrors() as $error) {
$exceptionMessage .= sprintf("[%s] %s\n", $error['property'], $error['message']);
}
throw new \Exception($exceptionMessage);
}
echo "valid"; |
Yes, Same if $_Input and $_Schema are json_decode($_Input, true) and json_decode($_Schema, true) |
Hello. Note that the json-schema implementation doesn't support draft-04 of the JSON Schema specification. I have resolved all of the draft-03 bugs and issues with Pull Request #41 with the exception of $ref, $schema, and id. Plus, I have fixed a few other issues as well. Merging #41 will be a big step towards supporting draft-03. #41 may also fix this issue as well. I would have to check that. |
#41 was merged May 28, 2013 |
When i put invalid datas to $validator->check(), nothing happens. For example, array instead of object.
The text was updated successfully, but these errors were encountered: