Search code examples
cerberus

How do i do an type OR Type. String OR Int?


I would like to be able to allow a string or an integer in a field. How do I do this?

This is my current schema:

    'minSize': {'type': 'any'},

Solution

  • I'm quoting the docs:

    A list of types can be used to allow different values

    >>> v.schema = {'quotes': {'type': ['string', 'list']}}
    >>> v.validate({'quotes': 'Hello world!'})
    True
    >>> v.validate({'quotes': ['Do not disturb my circles!', 'Heureka!']})
    True