Created
December 29, 2017 01:33
-
-
Save reece/d0cd1ca22cc38b9b6da5ad2b52f7c337 to your computer and use it in GitHub Desktop.
pjs-literal-issue.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# schema from README.md | |
schema = """ | |
{ | |
"title": "Example Schema", | |
"type": "object", | |
"properties": { | |
"firstName": { | |
"type": "string" | |
}, | |
"lastName": { | |
"type": "string" | |
}, | |
"age": { | |
"description": "Age in years", | |
"type": "integer", | |
"minimum": 0 | |
}, | |
"dogs": { | |
"type": "array", | |
"items": {"type": "string"}, | |
"maxItems": 4 | |
}, | |
"address": { | |
"type": "object", | |
"properties": { | |
"street": {"type": "string"}, | |
"city": {"type": "string"}, | |
"state": {"type": "string"} | |
}, | |
"required":["street", "city"] | |
}, | |
"gender": { | |
"type": "string", | |
"enum": ["male", "female"] | |
}, | |
"deceased": { | |
"enum": ["yes", "no", 1, 0, "true", "false"] | |
} | |
}, | |
"required": ["firstName", "lastName"] | |
} | |
""" | |
import tempfile | |
tf = tempfile.NamedTemporaryFile() | |
tf.file.write(schema.encode("utf-8")) | |
tf.file.close() | |
import python_jsonschema_objects as pjs | |
builder = pjs.ObjectBuilder(tf.name) | |
ns = builder.build_classes() | |
Person = ns.ExampleSchema | |
james = Person(firstName="James", lastName="Bond") | |
print(james.firstName.startswith("J")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment