-
-
Notifications
You must be signed in to change notification settings - Fork 590
Relative URI $refs returning "unknown url type" #313
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
Hi Ken, What ive done is hack the code. Because the uri is just "", the urlopen creates an exception. This is my hack to work around the issue. Ive just come up with this so no guarantee its correct or robust, but i can now validate a instance against a schema that references other schemas.
Derek |
Thank you, Derek! This patch worked for me after I removed the encoding= argument as I was getting the "'encoding' is an invalid keyword argument for this function" error. Perhaps because I'm running 2.7. I appreciate the input! I hope a fix of some kind is folded into the package so that I don't have to ask my users to hack their implementation. . . . . . . Ken |
I'm not sure when I'll have a second to look at this still, would still love some attention from some people with deeper URI knowledge ( #274 is probably relevant) but this specific case is probably a bug in E.g.:
and
which most likely has to do with the fact that Comments welcome. |
I agree "file:foo.json" may have no meaning ... I've never been able to get something like that to work. However, I'm quite confident that without a protocol identifier (e.g. "file:", "http:", "mailto:", etc.) at the beginning of the URI, the URI is considered relative and thus is resolved relative to the URI of the resource that is doing the pointing. Certainly in my work in XML (I founded the XML Conformance Committee in 1997) that has been the case with URI resolution. In my attached example you will find the URIs all have no protocol identifier so I am expecting the resolution to be relative to the resource doing the pointing. Certainly the modification suggested by Derek is working for me (with my modification for my environment)! Perhaps that could be folded in to the code in the short term. Thank you, very kindly, for having thought about this issue. While I personally think it very important, as it was for Derek, I'm confident others will as well. |
Just to clarify -- I agree about being relative to the pointing thing, my point was that once you've loaded it out of a file, there is no more scheme, you've just got an in memory thing with no reference to what scheme it was referred to by, which is why being "relative" to that is slightly ill defined |
Good point ... thanks for that clarification. Please forgive my oversight. But isn't the "in memory thing" an amalgam of its parts? Is there utility in maintaining its fragmentation? Does referencing happen after the amalgam has been built? Have my tests been too simple not to reveal a future problem? I have been testing handcrafted segments that will mimic the referencing of a library of 2574 declarations. This library is referenced from 81 "base" schemas. So, for me and my users, this referencing fragmentation facility is very important. The paper that I'm writing is referenced from and described in this post: https://lists.oasis-open.org/archives/ubl-dev/201612/msg00001.html I will soon be publishing the results and I need to point readers to a JSON validator that supports the fragmentation. For now I can work with Derek's hack during my development. |
I backed out the hack i did and went with the workaround in this thread. I ended up with this code. with open(sInstFile, encoding='utf-8') as fh: with open(sSchemaFile, encoding='utf-8') as fh: 2 lines to workaround the issue.sSchemaDir = os.path.dirname(os.path.abspath(sSchemaFile)) jsonschema.validate(dInst, dSchema, resolver = oResolver) |
Thank you, very kindly! That works for me as well and now I can ship a validator that works with Julian's distribution. I appreciate all of the input from both of you! Thank you. And happy holidays! . . . . . . . Ken |
In my work today I discovered the workaround breaks local relative references as in:
There is an example at https://spacetelescope.github.io/understanding-json-schema/reference/combining.html#allof where the use of "#/definitions/address" is used to reference a local declaration. I'll try to conceive a patch, but thought I would post this first in case anyone immediately sees what is needed. |
This appears to support both internal and relative URIs:
I'm not sure if there is a better patch or not because my tests are quite limited so far. I'll continue with my JSON project and if I find the above doesn't work for me in all my personal situations, I will post accordingly. I hope this input is considered helpful. |
Here is another puzzler that I can't (yet) wrap my head around: This is the program running under Mac/BSD:
This is the program running under VirtualBox/Windows10 from the very same shared directory:
Because it is a shared directory, I know it is the same copy of the program running on the same data. So I conclude the resolution error is coming from inside the library and not from my code. The leading "\" is suspect. Can anyone think of why the resolver isn't working on Windows? Again, I'll look at it myself, but I'm hoping someone will have an "aha!" moment before I get around to fixing this on my own. Thanks! . . . . . . Ken |
(Edited to expose the resolution_scope value) Next piece of evidence on this issue is related to this code (my diagnostic print directives added):
In Mac/BSD an ancestral relative reference is correctly being resolved:
In VirtualBox/Windows10 that same relative reference is not correctly being resolved:
Note how the "../" in VirtualBox/Windows10 is not being interpreted as "go up one directory from base directory" the way that it is correctly being interpreted in Mac/BSD. |
Hello, With the attached patch, this code works for me (on linux) for local and remote references
|
Has patch from @xalperte been accepted into this project? I also need relative file references. |
It hasn't, but I'm happy to merge it if someone puts together a PR with tests. |
@Julian is this fix merged to 3.0.a4 beta release |
Using the schema directory is a workaround , refering a schema network location would be fixed part of which issue |
It isn't, no, it still needs a fix. |
In the process: - Added `validate_functional_test_cases` script that does JSON schema validation - Updated foreign references to be to local files (not URLs) - Fixed JSON bugs in two of the schema files - Learned a hack (via [1]) for getting `jsonschema` to work correctly with `$ref` to a file Doing this revealed that several of the 3 curve intersections and 46 surface intersections **do not** adhere to the schema. [1]: python-jsonschema/jsonschema#313
Hi everyone, First of all, thank you for proposed workaround with custom resolver it helped a lot. As it was mentioned above, it doesn't work for Windows though. So, I made it work with next simple change, instead of providing base_url that starts with 'file://' I changed it to 'file:'. It works fine for me on Linux, MacOS, Windows. |
The mentioned workarounds don't work for me. The custom resolver seems to be ignored or at least on Windows I can't get it to work even with the mentioned fixes for Windows. Currently this is where the issue with relative local references occures: https://github.com/Julian/jsonschema/blob/master/jsonschema/validators.py#L774
|
Almost three years after reporting this problem I'm back to looking at this again and today I did a "pip install jsonschema" of the latest. I'm continuing to get an "unknown url type" error with a relative URI:
The project is documented here: The command I used today (in place of the commands found in the
|
0f344a69 Merge pull request #313 from leadpony/issue309 46c44747 Replace the control escape \\a with \\t 1ffe03e5 Merge pull request #312 from gregsdennis/master de004798 better descripttions eea7f249 arrays have characters too 7c02d06d added unevaluatedProperties test file; resolves #310 1899a5aa Merge pull request #308 from aznan2/master 4a5010b3 Update the version list. 37569b13 issue #307 - made test compatible with draft4 e3087307 issue #307 - removed issue reference from description e13d3275 issue #307 - removed pound sign from description a3b9f723 issue #307 - test that oneOf handles missing optional property git-subtree-dir: json git-subtree-split: 0f344a698f6657441adf4ebf4ceeacd596683422
Hi, sorry this took ages to look at. Both versions seem to work at least now here, though the relative version needs you specifying what base URI you mean to resolve against. E.g. you can use:
if you mean to have references resolved relative to the parent of the Feel free to follow up (OP or anyone else) in a new issue if there are any further things which look like bugs (or gaps in the documentation). |
pythonProblem-gkholman-20161212-2130z.zip
Attached is a ZIP with a JSON instance and two JSON schemas. One uses absolute URIs for $refs (you'll have to edit them for your own environment), the other uses relative URIs. An example documenting the use of relative URIs is at https://code.tutsplus.com/tutorials/validating-data-with-json-schema-part-2--cms-25640
Using jsonschema-2.5.1-py2.7 the schema with relative URIs returns "unknown url type". The schema with absolute URIs runs successfully.
I hope this example helps. Thanks for creating this library!
. . . . . Ken
The text was updated successfully, but these errors were encountered: