You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found nothing relevant to my problem in the docs.
I found the documentation not helpful to my problem.
I have the capacity to improve the docs when my problem is solved.
I have the capacity to submit a patch when a bug is identified.
Use-case abstract
I suggest adding support for using iterables in the "allowed" validation rule. In particular, I have a string enum class derived from enum.Enum. An enum.Enum is iterable. I'll try to demonstrate my use case:
classMyEnum(StrEnum):
FOO='FOO'# Behavior of MyEnum# list(MyEnum) -> [<MyEnum.FOO: 'FOO'>]# 'FOO' in MyEnum -> True# 'BAR' in MyEnum -> False# MyEnum.FOO in MyEnum -> True# MyEnum.FOO == 'FOO' -> True# MyEnum.FOO == 'BAR' -> False# This works, but is undesirable:schema= {
'foo': {'type': 'list', 'allowed': list(MyEnum)},
}
v=cerberus.Validator(schema)
# v.validate({'foo': [MyEnum.FOO, 'FOO']}) -> True# This raises an error:schema= {
'foo': {'type': 'list', 'allowed': MyEnum},
}
v=cerberus.Validator(schema)
# Traceback (most recent call last):# File "<input>", line 1, in <module># File "C:\Python36\lib\site-packages\cerberus\validator.py", line 169, in __init__# self.schema = kwargs.get('schema', None)# File "C:\Python36\lib\site-packages\cerberus\validator.py", line 509, in schema# self._schema = DefinitionSchema(self, schema)# File "C:\Python36\lib\site-packages\cerberus\schema.py", line 69, in __init__# self.validate(schema)# File "C:\Python36\lib\site-packages\cerberus\schema.py", line 197, in validate# self._validate(schema)# File "C:\Python36\lib\site-packages\cerberus\schema.py", line 219, in _validate# raise SchemaError(self.schema_validator.errors)# cerberus.schema.SchemaError: {'foo': [{'allowed': ['must be of list type']}]}
The text was updated successfully, but these errors were encountered:
afaict, supporting this would just require to change the rule's constraint schema to type.collections.Container. therefore the schema validator would need a type definition for that. that shouldn't be too tricky once you wrapped your head around the schema validation mechanics.
Mind filling me in on the mechanics? I've been looking for usages of _validate_allowed and can't see where it is used. Is there some autogen tooling built around the rule schemas?
Used Cerberus version / latest commit: 1.2
Python version: 3.6.5
I consulted these documentations:
I found nothing relevant to my problem in the docs.
I found the documentation not helpful to my problem.
I have the capacity to improve the docs when my problem is solved.
I have the capacity to submit a patch when a bug is identified.
Use-case abstract
I suggest adding support for using iterables in the "allowed" validation rule. In particular, I have a string enum class derived from enum.Enum. An enum.Enum is iterable. I'll try to demonstrate my use case:
The text was updated successfully, but these errors were encountered: