Skip to content

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

Closed
ghost opened this issue May 22, 2013 · 6 comments
Closed

Silence error #42

ghost opened this issue May 22, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented May 22, 2013

When i put invalid datas to $validator->check(), nothing happens. For example, array instead of object.

@justinrainbow
Copy link
Collaborator

Could you provide some example data?

@ghost
Copy link
Author

ghost commented May 22, 2013

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"!

@justjico
Copy link

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";

@ghost
Copy link
Author

ghost commented May 26, 2013

Yes,

Same if $_Input and $_Schema are json_decode($_Input, true) and json_decode($_Schema, true)

@mchiocca
Copy link

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.

@bighappyface
Copy link
Collaborator

#41 was merged May 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants