summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Willhaus <mail@janwillhaus.de>2019-05-15 23:22:52 +0200
committerJan Willhaus <mail@janwillhaus.de>2019-05-18 19:10:15 +0200
commit02354094d45398da7babe0f555e1c360c58fd467 (patch)
treefc60cab489d4f515741fd4d3b63fccaf686b7ffe
parent732ae48ea42d89d1c5a93df2cb363ad88e7ce6ff (diff)
downloadwarlock-02354094d45398da7babe0f555e1c360c58fd467.tar.gz
Declare codeblocks as python for REPL-looking `>>>`
-rw-r--r--README.md14
1 files changed, 12 insertions, 2 deletions
diff --git a/README.md b/README.md
index abba83e..ec3e1c1 100644
--- a/README.md
+++ b/README.md
@@ -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"}]'
+ ```