Open phiweger opened 7 years ago
from jsonschema import validate
from zoo.schema import fps, combine
instance = {'_id': '1', 'seq': 'ACTG'}
fragments = ['core', 'derivative']
schema = combine(fps(fragments), additional=False, required=None)
validate(instance, template) # returns None, all's well
# add a property, which is not one of the allowed properties
instance['foo'] = 'bar'
validate(instance, template) # throws ValidationError
def is_valid(instance, ):
'''Validate a hash map against a zoo JSON schemas.
zoo compose --fp /optional/path core,derivative(allow,recursion?) template.json
# if it does not find them at top directory will recursively enter subfolders, like node_modules
# --allow_additonal_fields --required _id,seq,foo,bar
zoo init --validate path/to/template.json
'''
...
I think the recursive definition is better than using JSON links/references, bc/ it is more explicit and because the latter are defined/ specified in such a variety of ways, that there seems to be not single best solution but a couple of hacky ones.
...