Skip to content

Commit 6174f5d

Browse files
Merge pull request #98 from gridsmartercities/validators
added validator creation example
2 parents ec24c67 + 4ad3e60 commit 6174f5d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,26 @@ def cors_example():
406406
cors_example() # returns {'statusCode': 200, 'headers': {'access-control-allow-origin': '*', 'access-control-allow-methods': 'POST', 'access-control-allow-headers': 'Content-Type', 'access-control-max-age': 86400}}
407407
```
408408

409+
## Writing your own validators
410+
411+
You can create your own validators by inheriting from the Validator class.
412+
413+
Fix length validator example:
414+
415+
```python
416+
class FixLength(Validator):
417+
ERROR_MESSAGE = "'{value}' length should be '{condition}'"
418+
419+
def __init__(self, fix_length: int, error_message=None):
420+
super().__init__(error_message=error_message, condition=fix_length)
421+
422+
def validate(self, value=None):
423+
if value is None:
424+
return True
425+
426+
return len(str(value)) == self._condition
427+
```
428+
409429
## Documentation
410430

411431
You can get the docstring help by running:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
LONG_DESCRIPTION = open("README.md").read()
44

55
setup(name="aws-lambda-decorators",
6-
version="0.39",
6+
version="0.40",
77
description="A set of python decorators to simplify aws python lambda development",
88
long_description=LONG_DESCRIPTION,
99
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)