Skip to content

Conversation

@boronine
Copy link

Excellent work on jsonschema.

I implemented enough $ref support to satisfy our requirements by integrating JSON pointer (https://github.com/stefankoegl/python-json-pointer). When $ref is a URL, it fetches the JSON document not from the internet, but from a dictionary passed into the validator's constructor. I also wrote some very basic tests.

A couple of notes:

  1. jsonpointer isn't packaged for Python 3.2
  2. setup.py probably shouldn't import __version__ from the module See https://bitbucket.org/hpk42/tox/issue/42/dependencies-should-be-installed-one-at-a
  3. validate_ref depends on self.schema for local pointers. When validate_ref is run from check_schema, self.schema is not set. I wrote a workaround, not sure if it's kosher though. See https://github.com/boronine/jsonschema/blob/48655a50a8d7c119b5bff7b110c53cdfc91f0959/jsonschema.py#L205

$ref support isn't quite there yet, but I hope it will come soon!

@Julian
Copy link
Member

Julian commented Oct 26, 2012

Hi there :).

Thanks for working on this. There's already partial $ref support implemented in #23 that I am about to merge. Did you have a look at that first by any chance? It implements local pointer support probably similarly to this, and the reason I haven't merged it yet is just because of your point 3, which should be resolved shortly (by making Draft3Validator.check_schema a classmethod, as it should be).

Regarding 1, despite the fact that I hate NIH, JSON Pointer is pretty simple, so I'm not so bothered by implementing it ourself, especially if it'd need Python 3 porting anyhow to use that existing implementation. In general I also hate being weary of adding dependencies, but here I think we want to be a bit careful, because jsonschema is being used in a couple of core packages in some distros IIRC, which will be weary of adding more packages that don't already exist.

As for 2, that issue seems to be talking about importing other packages, not the one being installed. I've seen that issue before, and if I recall correctly it's an issue only because that other package must obviously be present and installed first to import it. That shouldn't be an issue here. Please correct me if you've found one.

@boronine
Copy link
Author

My main requirement was preloaded URL support, which wasn't implemented in the other pull request, then I decided to integrate python-json-pointer based on NIH, though your reasoning against it makes sense too.

@Julian
Copy link
Member

Julian commented Oct 26, 2012

Ah, OK great glad we're on the same page.

Preloaded URL support is important, I'd like to get to that right after the other one is merged then.

@Julian
Copy link
Member

Julian commented Nov 7, 2012

OK, think this is essentially implemented in 2690f94.

Need to document it, but essentially the way to do this now is:

from jsonschema import RefResolver, Draft3Validator resolver = RefResolver(store={ "http://example.com/schema" : my_schema, "http://another.com/another" : another_schema }) validator = Draft3Validator(schema=some_schema, resolver=resolver)

Further support for retrieving uncached non-local refs is upcoming I hope.

@Julian Julian closed this Nov 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Some new desired functionality

2 participants