-
Notifications
You must be signed in to change notification settings - Fork 356
False passes with file loaded schemas. #340
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
Confused. Isn't that what you're demonstrating in your sample? I just gave it a try and it seemed to work for me, but that may be because I have written my own UriRetriever (because the default UriRetriever never seems to work for me). Have you verified with certainty that |
So inline means I literally define it as a variable within the code: $json = { ... } File based schema means I include it as follows:
As I mentioned. The following methods work as expected:
If, as in my example, I use a file based schema and an inline json declaration it doesn't work. To answer your questions - if I do the following:
I get the schema as I'd expect:
To show it's not working, I run the following:
The result:
This should fail, as there is a requirement for Apart from the slightly laravel changes ( |
Gotcha. Still can't reproduce, though. Can we see your full code sample, including the declaration of your validator (and any dependency injections)? |
Ok, you pretty much have it, but here's all the relevant bits of info and code: Laravel 5.3 include in
The class:
The
The method:
The schema:
The output:
As discussed, the last result should be Note, I have also tried this with a non empty json packet, for example:
Cheers |
I don't see anything obviously wrong with any of that. At this point, I'm afraid the best advice I can give you is to fire up the debugger and start stepping through. We know you can get things to work as expected by doing it inline, so I would start by debugging that to get a feel for how the flow should work, then going through it again with the file-based version. Let us know what you find out! |
Roger that. I've got a few things to finish on the project first, so I'll have to prioritise them. |
I don't know if you're still working on this, but is it possible that the only problem is that you're missing a call to |
@elb98rm I think you're using an old version of the library - recommend you update it. I've done some testing, and it looks like this was fixed in 3.0.0, but is a problem in older versions. If you are using a version >= 3.0.0, or if you can reproduce it >= 5.1.0 please let us know - otherwise I think we can probably consider this issue closed. Tests used to reproduce: /tmp/schema.json{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Foo",
"description": "Properly defines a Foo",
"type": "object",
"properties": {
"foo_id_text": {
"description": "UUID for this Foo",
"type": "string"
}
},
"required": [
"foo_id_text"
]
} Test script<?php
require('vendor/autoload.php');
use JsonSchema\Validator;
$validator = new Validator();
$schema = json_decode('{"$ref":"file:///tmp/schema.json"}');
$invalidInput = json_decode('{}');
$validInput = json_decode('{"foo_id_text":"stringValue"}');
$validator->check($validInput, $schema);
assert($validator->isValid() === true);
$validator->check($invalidInput, $schema);
assert($validator->isValid() === false);
echo("Test completed OK\n"); |
Thanks for the feedback. I'll look at this shortly and respond. |
@elb98rm Did you have a chance to look at this? |
Sorry - this got lost in a development cycle: I'll have an answer for you this weekend. |
@elb98rm 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 this is a rather old issue, which sadly was left unanswered, and can be closed? Feel free to close it yourself with some comments if helpful. |
Yup. I've moved on: you can clean up the ticket! :) |
I'm working on a laravel project (so please excuse any framework specific functions), and I'm noticing false positives on the validation tests.
The system is part of a restful api, and as such I'm validating all requests for item creation.
If I define the following schema (
docs/json/test_schema.json
):Inside my controller, I have the following:
... then I get:
bool(true)
Note that:
... it behaves as expected (i.e :
bool(false)
I've reduced this to such a low level I think it is actually a bug. Can you please investigate (alongside me).
Cheers
Rick
The text was updated successfully, but these errors were encountered: