python-jsonschema / jsonschema

An implementation of the JSON Schema specification for Python
https://python-jsonschema.readthedocs.io
MIT License
4.6k stars 578 forks source link

Beyond validation #107

Closed dbinit closed 11 years ago

dbinit commented 11 years ago

Hi, great project.

Do you have any plans to provide more than validation with your project? In particular, it would be great if the schema+instance walking were abstracted so that it could be used for other things.

In my case, I would like to apply transformations before validation.

Julian commented 11 years ago

Thanks :).

This project is going to stick with just implementing the spec, but I do have similar ideas and desires as you might (and a few other people have expressed interest), so recently we've started up https://github.com/Julian/Seep which will handle the layer on top of just strictly validation. I encourage you to check that out and voice whatever ideas you have in mind, since right now it's in planning stages on two vomited-out Wiki pages.

I don't have tons of time right now, so my desire to make time for Seep will likely be motivated by the presence of others who are willing to do some of the chunks of work on that project – or more accurately, who are willing to do some organizing and planning, and administrating :D. Although, at least with the ideas I currently have there none of that is really that difficult so far.

dw commented 11 years ago

Hi there,

Our team have two use cases not covered by jsonschema that we're going to need in short order. The first is as described by this ticket – the ability to walk the schema. The second is access to the default property.

In both cases my only apparent option is to cutpaste the guts of jsonschema and produce such an abstraction myself.

Some kind of schema visitor is useful in a bunch of circumstances, for example:

I admire your work on seep – but it seems unless you plan to mostly reimplement this module as part of seep, some kind of generalization of jsonschema internals will be needed at some point :)

Julian commented 11 years ago

I'm not sure I've fully understood the two things you're asking for, but they certainly don't require copying and pasting any internals.

jsonschema has quite a decent extension API if I don't say so myself. It's partially documented here in the docs.

In particular, though schema traversals are really unspecial (it's a Python dict, you can traverse them as you always do) if you wanted to traverse them while the validation is occurring that's pretty much exactly what the extension API is for, and is how Seep works: https://github.com/Julian/Seep/blob/master/seep/core.py#L17

I don't know what kind of thing you want to do with ‛default` but whatever it is is probably possible in the same way. If what you want is to fill in defaults on your instance or whatever there's a FAQ entry that'd get you started here: https://python-jsonschema.readthedocs.org/en/latest/faq/

Hope this helps. Julian