diff --git a/functions/validate_values.py b/functions/validate_values.py index 2159269..53469f6 100644 --- a/functions/validate_values.py +++ b/functions/validate_values.py @@ -13,12 +13,18 @@ def create_dynamic_schema() -> Type[Schema]: for attrib in item_attributes: if isinstance(attrib, textAttribute): + # Allowed chars + def validate_allowed_chars(value: str, attrib=attrib) -> None: + if attrib.allowed_chars and not all(char in attrib.allowed_chars for char in value): + raise ValidationError(f"Invalid characters in {attrib.display_name}. Allowed characters are: {attrib.allowed_chars}") + schema_fields[attrib.attrib_name] = fields.String( required=attrib.required, validate=[ lambda x, attrib=attrib: len(x) <= attrib.max_length if attrib.max_length else True, lambda x, attrib=attrib: len(x) >= attrib.min_length if attrib.min_length else True, lambda x, attrib=attrib: re.match(attrib.regex, x) if attrib.regex else True, + validate_allowed_chars, ], error_messages={ "required": f"{attrib.display_name} is required.",