diff options
author | Jan Willhaus <mail@janwillhaus.de> | 2019-05-15 23:22:52 +0200 |
---|---|---|
committer | Jan Willhaus <mail@janwillhaus.de> | 2019-05-18 19:10:15 +0200 |
commit | 02354094d45398da7babe0f555e1c360c58fd467 (patch) | |
tree | fc60cab489d4f515741fd4d3b63fccaf686b7ffe | |
parent | 732ae48ea42d89d1c5a93df2cb363ad88e7ce6ff (diff) | |
download | warlock-02354094d45398da7babe0f555e1c360c58fd467.tar.gz |
Declare codeblocks as python for REPL-looking `>>>`
-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"}]' + ``` |