Skip to content
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

on validation error, path to wrong item is false when "anyOf" is used #360

Closed
xjlm opened this issue Sep 13, 2017 · 8 comments
Closed

on validation error, path to wrong item is false when "anyOf" is used #360

xjlm opened this issue Sep 13, 2017 · 8 comments

Comments

@xjlm
Copy link

xjlm commented Sep 13, 2017

Hi

when a schema contains a "recursive" structure inside a "anyOf", and there is an error in a related json file deep in the hierarchy, then the validator finds the error but indicates a wrong path:

python check.py

INFO validate file 'data.json' ...
ERROR validate file 'data.json' FAIL
ERROR {u'CONTENT': [{u'CONTENT': [{u'CONTENT': [{u'TYPE': u'CHAPTER', u'TITLE': u'chapter_55555'}], u'TYPE': u'CHAPTER', u'TITLE': u'chapter_4'}], u'TYPE': u'CHAPTER', u'TITLE': u'chapter_3'}], u'TYPE': u'CHAPTER', u'TITLE': u'chapter_2'} is not valid under any of the given schemas *** deque([u'CONTENT', 0, u'CONTENT', 0])

Note that the online validator https://json-schema-validator.herokuapp.com finds many errors but at least indicates the error concerning the string being too long and its path

see attached files schema.json and data.json

@xjlm xjlm closed this as completed Sep 13, 2017
@xjlm xjlm reopened this Sep 13, 2017
@xjlm xjlm changed the title on validation error, path to wrong item is false on validation error, path to wrong item is false when "anyOf" is used Sep 13, 2017
@xjlm xjlm closed this as completed Sep 13, 2017
@xjlm
Copy link
Author

xjlm commented Sep 13, 2017

BUG_VALIDATION.zip

@xjlm xjlm reopened this Sep 13, 2017
@xjlm
Copy link
Author

xjlm commented Sep 13, 2017

Note that when the schema is written without "anyOf", then the error and its path are perfectly reported.

@Julian
Copy link
Member

Julian commented Sep 13, 2017

Hi.

I'm not sure I fully follow what you're calling the bug, but I think you're just referring to the fact that jsonschema will not recurse into an anyOf (even one that only has one branch) when reporting an error -- doing so (in the general case) doesn't make too much sense, because there are multiple places in the instance that were wrong, one for each branch of the anyOf.

Please have a look at http://python-jsonschema.readthedocs.io/en/latest/errors/#best-match-and-relevance though, which do try to guess which error you probably want to see.

@xjlm
Copy link
Author

xjlm commented Sep 14, 2017

Hi.

Unfortunately the "best match" cannot help, as I only get 1 error. The error message seems actually to be OK, und unfortunately not very helpful.

In the example (data.json), there is a string of length 13 ("chapter_55555"), although the schema imposes a maxLength of 10.
What I am expecting is something like this (as in https://json-schema-validator.herokuapp.com)

...
"instance" : {
"pointer" : "/CONTENT/0/CONTENT/0/CONTENT/0/CONTENT/0/CONTENT/0/TITLE"
},
"domain" : "validation",
"keyword" : "maxLength",
"message" : "string "chapter_55555" is too long (length: 13, maximum allowed: 10)",
"value" : "chapter_55555",
"found" : 13,
"maxLength" : 10
} ]
}
...

which clearly reports the error, even if there are many other errors (noise) reported concerning "anyOf".

But jsonschema does not report at all somethings related to the string "chapter_555555" being to long.

Sincerely,

xjlm

@Julian
Copy link
Member

Julian commented Sep 14, 2017

Still not quite sure what you mean, did you read that doc page? best_match gives you exactly that kind of information (and for your case it gives you exactly that error).

@xjlm
Copy link
Author

xjlm commented Sep 15, 2017

Hi,

Yes, you're perfectly right, I did not try "best_match" ... sorry.
So now I get as you said this error message:

ERROR u'chapter_55555' is too long *** deque([u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'TITLE'])

But unfortunately I've just try this 'best_match' with an other schema (with an "anyOf" containing 2 items) and another json data, and the error message seems NOT to be OK to be:

python check.py

ERROR u'DATA' is not one of [u'CHAPTER'] *** deque([u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'TYPE'])

I am waiting:

ERROR u'data_5555555' is too long *** deque([u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'CONTENT', 0, u'TITLE'])

What do you think about it ?

Sincerely,

xjlm

PS: check.py, data.json and schema.json in BUG_VALIDATION2.zip
PPS: please feel free to close the ticket if you think I am wrong

BUG_VALIDATION2.zip

@Julian
Copy link
Member

Julian commented Sep 15, 2017 via email

@xjlm
Copy link
Author

xjlm commented Sep 16, 2017

closed because it may be an user error

@xjlm xjlm closed this as completed Sep 16, 2017
Julian added a commit that referenced this issue Aug 13, 2020
86f52b87 Fix a clear copy-paste error in the case names for tests from #394.
ec18a7d0 Merge pull request #360 from notEthan/duplicate_uris
cd9a4b9d change schemas with duplicate URIs http://localhost:1234/folder/
43e190e0 Merge pull request #394 from rjmill/rjmill/bools-and-1s-and-0s-inside-objects-and-arrays
85f0d459 Merge pull request #419 from ChALkeR/chalker/format-uri
54436216 Merge pull request #420 from ChALkeR/chalker/format/ip6
ad47b726 Add long valid and invalid ipv6
b2ab70ec More optional ipv6 tests
37189ae6 Test that uri format scheme is validated for allowed chars
2106ed17 backport uniqueItems cases to draft3
49fc2a95 backport const test cases to draft6
79fe60c0 more tests for true != 1 and false != 0 inside objects/arrays

git-subtree-dir: json
git-subtree-split: 86f52b87e3d572b8f808dd074a6b95c3695ba992
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

2 participants