1

I need to set the minimum and maximum length of a list between 2 - 5. Is there a way to specify this in Python Cerberus. Here's what I have currently but this allows lists of all sizes:

  {
    "levels": {
        "type": "list",
        "schema": {
            "type": "string",
            "required": True,
            "nullable": False,
            "empty": False,
        },
        "required": True,
    },
}
flyingfox
  • 13,414
  • 3
  • 24
  • 39

1 Answers1

1

You can use minlength/maxlength rules in your schema for your list -

{
    "levels": {
        "type": "list",
        "minlength": 2,
        "maxlength": 5,
        "schema": {
            "type": "string",
            "required": True,
            "nullable": False,
            "empty": False,
        },
        "required": True,
    },
}

This will make sure that length of levels list is between 2-5.

Jay
  • 2,431
  • 1
  • 10
  • 21