Skip to content

Instantly share code, notes, and snippets.

@reece
Created December 29, 2017 01:33
Show Gist options
  • Save reece/d0cd1ca22cc38b9b6da5ad2b52f7c337 to your computer and use it in GitHub Desktop.
Save reece/d0cd1ca22cc38b9b6da5ad2b52f7c337 to your computer and use it in GitHub Desktop.
pjs-literal-issue.py
#!/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