Skip to content

Allow fetching of subschemas from file URLs #132

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

Closed
lordjabez opened this issue Nov 8, 2013 · 5 comments
Closed

Allow fetching of subschemas from file URLs #132

lordjabez opened this issue Nov 8, 2013 · 5 comments

Comments

@lordjabez
Copy link

I love this validator! But one feature I'd like to see is for it to be able to load referenced sub-schemas from file as well as by URL.

I'd be happy to contribute this feature if it's desired, I'd just like to know how the file URL should be specified (in contrast to a typical HTTP URL). Should I use file:/// ? And what about relative file paths? I figure relative to the script path makes the most sense.

I already have this feature mostly working in my own fork, but will clean it up and submit a pull request soon.

Thoughts?

@Julian
Copy link
Member

Julian commented Nov 8, 2013

Hey!

So, RefResolver which is the relevant object here, should support whatever kind of URI you want to throw at it as long as it knows how to resolve them (hee hee circular :P, but what that means is that it knows about the relevant scheme, say). For files, it should already know how to do so.

E.g. if I have f1.json with a schema and I put {"$ref": "file:///Users/Julian/Desktop/f1.json"} in it, it "works". Can you describe what you're trying / provide an example?

I should mention that you can add your own scheme handlers to a ref resolver if you'd like too (see the handlers argument to RefResolver )

@lordjabez
Copy link
Author

Ahh, you're absolutely right. Not sure what I was doing wrong earlier, but it clearly works fine with a 'file:mydir/myschema.txt' URI.

Thanks for setting me straight!

@Julian
Copy link
Member

Julian commented Nov 8, 2013

No worries :) glad it works for you.

@bayandin
Copy link
Contributor

Hi!
I have another question about fetching schemas from file. Is it possible to fetch a schema from file by relative path.
For example, I have 2 files: /Users/bayandin/Desktop/f1.json and /Users/Julian/Desktop/f2.json
and I want to read f2.json from f1.json:

"$ref":"file://f2.json"

?

@bayandin
Copy link
Contributor

Ok, I figured out myself: "$ref": "file:f2.json" works for me.

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

3 participants