-
-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add JSON pointer support to $data reference. #289
Conversation
Not sure where the test code for $data is located. |
"format": "relative-json-pointer" | ||
"format": { | ||
"anyOf": ["relative-json-pointer", "json-pointer"] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not valid - should be anyOf
with two format
keywords inside.
Thank you for the PR!
|
I can say definitively from my own manual testing, absolute pointers cannot go higher than the root of a $ref ( As for everything else, I'll get those fixes and tests written up in a day or two. Thanks! |
Alright, I finished putting together the tests. The last two tests in the file I added are set to |
Thank you! I will try to fix this issue - I hoped that even if it doesn't go outside of $ref at least the value would be correct based on the absolute reference. From what you say it's even worse - it just points to the wrong value (in case the root for the ref is different from the data root). Docs need to be updated too, I will do it. |
@HotelDon I understand how to resolve the issue - the validation function should be passed an additional 5th argument - I don't think it will be a breaking change for anyone - It would only be breaking if somebody were passing additional arg(s) to compiled validating function (they could only be used in inline custom keywords). |
@@ -214,20 +214,33 @@ function getPath(currentPath, prop, jsonPointers) { | |||
} | |||
|
|||
|
|||
var JSON_POINTER = /^#|\/(?:[^~]|~0|~1)*?$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need "#"
in the pattern? If you mean it as the pointer to the root it should be ""
(an empty string) instead. "/"
is the pointer to the empty property at the top level. "#"
in relative json pointer is a special thing resolving to the name of the property/index rather than to data. Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. I forgot to take it out. The # sign at the start of a pointer DOES have a specific meaning for regular JSON pointers, but it's one that has no relevance to JSON schema, and I should have taken it out of the regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really: https://tools.ietf.org/html/rfc6901#section-3
It's when JSON pointer is in URI (in $ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh jeeze, I had never actually noticed that $refs are also JSON pointers. Now that you've pointed that out, I have noticed something. A $data reference formatted like a URI ("$data": "#/foo"
) will be considered valid in the schema, but the data won't validate. Formatting $ref as a non-URI pointer has a similar effct: "$ref": "/definitions/foo"
won't throw an error in the schema, but the data won't validate.
According to the JSON-schema spec, a $ref has to be formatted as a URI, and the $data proposal doesn't mention URI support at all (while I can think of some uses for it, it sounds like a potential security nightmare).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/defenitions/foo
is a valid relative URI (definitions is a folder and foo is a file), schema compilation fails because it cannot find schema with such uri.
But #/foo
is not a valid JSON pointer, it passes json-pointer format validation because I allowed (maybe mistakenly? Not sure, it's not precisely specified) URI encoded JSON-pointers in this format.
I don't think it's such a big deal to worry about, as long as you are aware that $data only takes normal JSON pointers it's fine. Allowing uri encoded JSON pointers would be a bit more effort that just stripping #, you'd need to decode as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I understand.
Thanks for all your help, by the way. This pull request solved a lot of headaches I was having. If you're ever near San Jose, I'll buy you a beer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha :) Thanks!
In 4.6.0 |
What issue does this pull request resolve?
Issue #285
What changes did you make?
I added support for regular JSON pointers to the $data reference
Is there anything that requires more attention while reviewing?
Make sure I didn't accidentally create the regex from hell when I used and modified the existing relative-json-pointer regex.