Skip to content

Instantly share code, notes, and snippets.

@abemusic
Created April 15, 2014 18:47
Show Gist options
  • Save abemusic/10758293 to your computer and use it in GitHub Desktop.
Save abemusic/10758293 to your computer and use it in GitHub Desktop.
Blueprint schema validation
BLUEPRINT_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Blueprint',
'description': '',
'type': 'object',
'required': ['title'],
'properties': {
'title': {
'type': 'string',
'minLength': 5
},
'description': {
'type': 'string',
'minLength': 10,
},
'hosts': {
'type': 'array',
'minItems': 1
}
}
}
BLUEPRINT = {
'title': 'Foo',
'description': ''
}
@abemusic
Copy link
Author

for error in jsonschema.Draft4Validator(BLUEPRINT_SCHEMA).iter_errors(BLUEPRINT):
        print error.message

'' is too short
'Foo' is too short

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment