diff options
-rw-r--r-- | README.md | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -6,6 +6,7 @@ Build self-validating python objects using JSON schemas. 1) Create your schema + ```python >>> schema = { 'name': 'Country', 'properties': { @@ -15,22 +16,28 @@ Build self-validating python objects using JSON schemas. }, 'additionalProperties': False, } + ``` 2) Create a model + ```python >>> import warlock >>> Country = warlock.model_factory(schema) + ``` 3) Create an object using your model + ```python >>> sweden = Country(name='Sweden', abbreviation='SE') + ``` 4) Let the object validate itself + ```python >>> sweden.name = 5 Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "warlock/core.py", line 53, in __setattr__ + File "<stdin>", line 1, in <module> + File "warlock/core.py", line 53, in __setattr__ raise InvalidOperation(msg) warlock.core.InvalidOperation: Unable to set 'name' to '5' @@ -40,9 +47,12 @@ Build self-validating python objects using JSON schemas. File "warlock/core.py", line 53, in __setattr__ raise InvalidOperation(msg) warlock.core.InvalidOperation: Unable to set 'overlord' to 'Bears' + ``` 5) Generate a [JSON Patch document](http://tools.ietf.org/html/draft-ietf-appsawg-json-patch) to track changes + ```python >>> sweden.population=9453000 >>> sweden.patch '[{"path": "/population", "value": 9453000, "op": "add"}]' + ``` |