-
Notifications
You must be signed in to change notification settings - Fork 66
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
Docs for local "$refs" #7
Comments
I believe it should work as described in the documentation you linked. Do you have an example I can use to reproduce your issue? |
I greatly appreciate you taking the time to look into this. Regardless of the outcome I think adding a couple examples of using local files as refs to the documentation would be very useful. Here's a gist with reproducible data: Note: the root schema is located in FWIW, these schemas work with |
It looks like the issue is your |
This works with 0 configuration in Regarding the lack of It is also my understanding from the spec and the definition of I will test out providing an absolute |
Those spec links are helpful, thanks. In this case, we don't know the URI where the schema was found, so I think this applies:
Not sure what a suitable substitute would be. Do you mean that |
Is this because I will experiment with generating the an absolute
Yes, it reads them from the file system with 0 config. The example I provided in the gist works with the following
Note: in this case, it knows where the schema was found as it accepts paths. |
Yeah, right now there's no way to know what the base URI should be for the schema hash. I'd rather not allow raw json, since it's pretty easy for someone to parse it into a hash themselves. I'll look into reading from files though. I'm a little wary of doing it automatically but it makes sense as an optional thing. |
Fair, but it seems very weird to implement a JSON spec that doesn't accept JSON. FWIW, I got it working with the following https://gist.github.com/tryangul/07f4a46b00cf244f2a95317966fb121e I still advocate adding something like this to the docs and or extending the ref resolver to allow for more easily setting this up. If you're willing, I'd happily make a docs PR and we can move discussion there. |
Also, probably for another issue, but while this is working, the output is less than ideal https://gist.github.com/tryangul/de71c05bf5d3553ecc8e433a113ab815 Is this related to #1 ? |
with ref resolver that reads from file system. Fixes: #7
with ref resolver that reads from file system. Fixes: #7
Glad to hear you got it working. You should try out this branch to see if it behaves like you expect: https://github.com/davishmcclurg/json_schemer/compare/file A docs PR would be great! Docs are basically nonexistent at this point. The error output for nested schemas is not good. There's been a lot of discussion about standardizing error output somehow: json-schema-org/json-schema-spec#396 json-schema-org/json-schema-spec#643 |
I have to say I'm struggling to understand how to use this gem with local files. I have a bunch of nested schemas and can't seem to validate a simple piece of data. I've tested the same nested schema (after expanding it) and it seems to validate fine. Am I missing something obvious here? |
Oh I wasn't aware of that. I'll see if I can get it working with strings. BTW, thanks for the gem man. Too many times people just come in complaining about issues/errors but before it all, know that you have my (probably everyone's) appreciation for the work you've put into it. |
I am having issues to trying to make external
I would like in the docs an example of a local ref working, please advice, and thanks for the hard work! |
Just an update for anyone else who runs into this. If you pass in a TL;DR:This: JSONSchemer.schema(Pathname.new('/my/awesome/schema.json')) Instead of: JSONSchemer.schema(File.read('/my/awesome/schema.json')) |
@jimeh I couldn't get this to work. Could you give an example of how you're referencing the files?
I tried using |
@Draiken you may need to use an absolute path when creating your |
@Draiken try giving filename = 'foobar.json'
file_path = File.expand_path(File.join('..', 'schemas', filename), __dir__)
JSONSchemer.schema(Pathname.new(file_path)) Also, the schema refs I've got don't use any { "$ref": "./broadcasts/connections.json" } |
I'd love to use the library, but I can't unless I can easily get local "$refs" working.
If this is supported, it could use some documentation / examples.
See https://json-schema.org/understanding-json-schema/structuring.html#reuse for what I'm talking about.
The text was updated successfully, but these errors were encountered: