Skip to content

Instantly share code, notes, and snippets.

@jason-s
Created January 6, 2015 18:02
Show Gist options
  • Save jason-s/6d2b3418f4edb7fc8064 to your computer and use it in GitHub Desktop.
Save jason-s/6d2b3418f4edb7fc8064 to your computer and use it in GitHub Desktop.
import yaml
import jsonschema
raw_schema = r'''
"$schema": "http://json-schema.org/draft-04/schema#"
type: object
properties:
debug: {$ref: "#/definitions/debug"}
required:
- debug
additionalProperties: false
definitions:
debug:
type: object
properties:
foo: {$ref: "#/definitions/foo" }
additionalProperties: false
required:
- foo
foo:
type: object
properties:
bar:
type: object
patternProperties:
"^[^\\d\\W]\\w*$":
type: string
additionalProperties: false
'''
raw_doc = '''
debug:
foo:
bar:
jiminy: cricket
mickey: mouse
44hoho: twinkie
'''
schema = yaml.safe_load(raw_schema)
doc = yaml.safe_load(raw_doc)
try:
jsonschema.validate(doc, schema)
except jsonschema.exceptions.ValidationError as e:
for k,v in vars(e).iteritems():
if not k.startswith('_'):
print '%-15s: %s' % (k,v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment