-
Notifications
You must be signed in to change notification settings - Fork 354
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
Documentation : Is the readme example actually working ? #299
Comments
PRs are welcome. I am not sure why you sent to SO first, but you are at the right place now. |
Well I was looking for help to solve my issue, in my mind I was doing something wrong. After being able to solve it and found where the problem was coming from, I am now felling a bit more confident to create an issue here. |
I see. You and all are welcome to raise an issue. We may not be the most responsive bunch, but we we are friendly and want to help. |
Glad to hear that @bighappyface, according to what you read here and in SO, do know where I messed up ? The example you are giving on the readme is supposed to work out of the box ? More basically I am looking for some documentation / resources about this project, describing the different features. I did find the 'docs' folder after cloning the repo, but there is nothing really new in comparison with the actual readme. Thank's for your help. |
@etiennechabert I have not had a chance to dive in yet. I'll try to get back to you in the next week or so (super busy with work and school). Thanks for your patience. |
Hi there, I have followed your stackoverflow thread and, even though I can see my schema and data being loaded, the 'check' method returns NULL. Any idea of why is this happening? I assumed that if there was something wrong loading the data and/or schema an Exception would be thrown but I'm just getting a NULL value so I cannot use any if the isValid or getErrors methods. My code is as follows:
|
Hey Buddy, You should ignore the return value from the check function. After the check just focus on $validator->isValid() which is going to return a boolean value. If you are interrested by an array of errors you should try $validator->getErrors(). Good luck ;-) |
Thanks for your reply @etiennechabert Unfortunately isValid() returns always true no matter what I pass in. I tried to add some garbage to the data and isValid() is still returning "true". Edit: okay, now it's validating the JSON properly. I think there was a problem with my schema definition :) thanks again for your help @etiennechabert |
Got you, so you are in the same situation than I was. Could you please give me the print_r output for your json_data and json_schema ? |
The problem (I think) is that json_decode() already parses and validates the JSON. If there are any syntax errors it will return "null", and if that's the case the validator will return "true". I don't know if this is a bug or a feature but maybe they author should look into that. |
json_schema role is not to check your JSON syntax validity, but to check the schema of the provided data. For example data_type, mendatory_value, extra properties and so on. For this reason you should first provide a correct JSON before trying to check his schema |
To be clear, these tests are being performed against 3.0.0? Are you encountering similar behavior on 2.0.5? |
I'm using 2.0.x and it just doesn't work. Source code has this comment:
I don't see how this code is suppose to work, it lacks the very basic function - to actually load json schema from a file and to compare it with in memory object (decoded json). I guess no one uses this package, that's why we are discussing such a basic issue here. It just does not work, plain and simple. Sorry. |
@stamster It would be interesting to have a look at the source code leading to a isValid() always returning true, you probably failed somewhere. Anyway I agree with you : the README exemple doesn't work and probably need to be fixed, but the library do work and I am actually using it to check user's input on a WS actually in production. |
I just used official example posted here on GH. If that fails (actually validates), w/o any error reported back - user cannot be doing anything wrong, it's the app which fails (i.e. broken). BTW, I took a 5 mins to try latest 3.0.x version, and guess what - it works. Documentation suggests 2.0 branch, which is obviously wrong and not working. That's the conclusion - by just upgrading to the new branch my code (official example) runs fine, so 2.0.x is totally broken. Nevertheless, I already have switched to another lib, which is, IMHO, much more cleaner. @etiennechabert thanks for reply! |
I have created new PR for README file change. |
@bighappyface Time to close this one? |
Closing for now, can re-open if needed |
I am using your library for few days and I struggled a bit at the beginning to make it work with a very basic case.
I did my best to follow your example, but it was not really helping :
I created this stackoverflow post with my issue, please feel free to read it : http://stackoverflow.com/questions/39042346/json-schema-required-properties-ignored/39048262?noredirect=1#comment65497165_39048262
The answer was not really helping, for this reason I finally execute my code and your library step-by-step to understand what was going on. To be honest I don't understand how your example could work. After debugging your code, I am not able to tell where you are loading the JSON schema.
Inside the UndefinedConstraint:validateCommonProperties function, where you are checking if required properties are in, my schema is not loaded yet.
As you can see in the stackoverflow post, I finally make it work by loading the schema myself.
I created this ticket because I get quite confused by your example, I am definitely missing something about it... Is it possible for you to add more details on how dummies like me are supposed to use it ;)
Best regards,
The text was updated successfully, but these errors were encountered: