I have been using marshmallow for API's request json validation ,Its a great Library . Now i came across a situation where i have to validate ENUM filed . I have a ENUM field called 'gender' which will expect 3 values ('Male', 'Female', 'Others'). So here how do i add this validation field to Schema. Below i have mentioned one example .
from marshmallow import Schema, fields, validate
class UserDetails(Schema):
user_id = fields.Integer(required=True, validate=validate.Range(min=0,
error="user_id is invalid, it should be a positive integer."))
user_name = fields.String(required=True, validate=validate.Length(min=1, error="Field should not
be empty."))
user_gender = ?
Thanks in Advanced .
See the docs:
https://marshmallow.readthedocs.io/en/stable/quickstart.html#validation
permission = fields.Str(validate=validate.OneOf(["read", "write", "admin"]))
Thanks a lot @lafrech
Most helpful comment
See the docs:
https://marshmallow.readthedocs.io/en/stable/quickstart.html#validation