-
Notifications
You must be signed in to change notification settings - Fork 280
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
Validation fails for JSON arrays when errors exist across multiple contained objects #36
Comments
I followed the guidelines for pull requests, and added my schema and JSON subject files to an
This is the same problem I had with the org.json library when I first started using it, which led to me writing my own code to figure out whether the input JSON was an object or an array before trying to read and validate it. It would be nice if the library had generic handling so that either an object or an array could be input, but that is another story. Bottom line: I think the IssueTest class will need to be modified before my JSON array input can be properly read. I suppose I will do just that... |
Hello @twbutler , In its current state the IssueTest is only able to reproduce issues like "an valid input has been found invalid by the library" or "an invalid input has been found valid by the library". On the other hand your issue is about reporting an inproper validation failure, and the IssueTest currently cannot assert if the proper ValidationException is thrown. Most probably first I will have to perform some redesign of this integration test runner. Thanks for reporting it anyway. |
Thanks for responding. Are you saying that since IssueTest would not support testing my particular issue, that I should not worry about submitting the pull request with my test data? The content I would be submitting in the files is the same as that given above in my first post... Thanks... |
Okay, I will just improve the testing infrastructure then I will go ahead with creating a proper reproduction with your inputs provided above. |
If it helps, I have already written a code segment in my cloned fork that allows IssueTest to read either JSON object or JSON array input without choking. Line 112 - instead of:
Use the following:
With this change, I can run the tests and they all pass. As you said, the assertions in IssueTest would need rework in order to flag the incorrect output of the messages list in CausingExceptions for my issue 36. |
Yes, and this part will need more work. We will need some way to describe the expected exception, which will be probably some sort of JSON notation. Anyway, this is not the first case when a bug related to If you feel adventurous and have the time to contribute then I can give you some hints about what I have in mind to improve IssueTest to make your problem reproducible. |
Sure, I have a bit of time - What did you have in mind? Could it be as simple as including a file (called something like expectedCausingExceptions.txt) with the expected causing messages listed one on each line? So, in my case, the file would include:
The test would look for the file, and if present, simply read each line into a List and then compare that List to the message content obtained from the getCausingExceptions() List... |
Not exactly, but not much more complicated. Lets call this file Example:
So the |
I see. Your design sounds good to me. I will start coding up some changes to support the expectedException.json file as you have suggested... |
Well.. I am having an "ah-ha" moment... ^_^ |
Yep, this issue was due to my incomplete understanding of the validation failure reporting mechanism. I now have better code that recursively processes all the sub-exceptions until all failures have been collected. Closing - and sorry for the noise. But hopefully, this can help others about to make the same mistake as I did... |
No problem. Anyway if you have any local changes regarding |
I did not get very far. The next step I had was to write code to read the new expectedException.json file and compare its contents to the actual failures output by the validation library... Well, since I agreed to help, I will give some more time to this and send you a PR... stay tuned. |
It doesn't have to be a polished implementation, I also don't mind a failing build, I just don't want your work to be lost. |
I think I am almost ready to issue the PR. However, first I wanted to ask about something else I found during this exercise that looks like a possible bug to me. It seems to me that the top level message contained in the first ValidationException thrown should report the correct total count of validation failures (e.g. "#: 3 schema violations found"). I just happened to notice a case in which I have 4 validation failures, but the top level message reports only 3. This is a minor issue in my thinking because all four failures are found and reported in the causingExceptions, it is just that the summary number is incorrect. But I thought I would see what you think. I plan to submit this case with my code that allows the expectedException.json file to be used to specify expected failures. |
Hello, I don't clearly see your point regarding the number of violations in the I'm looking forward to receive a PR from you in the upcoming days. Thank 2016-06-20 20:51 GMT+02:00 twbutler [email protected]:
Bence Erősme@github https://github.com/erosb |
You are at the wrong repository @shiragig . This is a java project, yours is a javascript error. |
When using the JSON validation library with JSON arrays, I have found a problem in which some validation errors are not reported. If the input JSON array contains multiple JSON objects, and validation errors exist in each of these objects, then only one error is reported in the CausingExceptions list, and the others go unreported. For instance, given the following schema:
And given the following input JSON array:
The expected validation failures are:
#/0/name: expected type: String, found: JSONArray
#/1: required key [price] not found
However, the CausingExceptions provide this output:
#/0: 2 schema violations found
#/1: required key [price] not found
I will work on a testcase as suggested by your guidelines...
Thank you!
The text was updated successfully, but these errors were encountered: