@@ -28,36 +28,38 @@ def validate_column(data, rules):
28
28
def validate_string (value , rules ):
29
29
issues = []
30
30
if 'minLength' in rules and len (value ) < rules ['minLength' ]:
31
- issues .append (f"String is shorter than the minimum length of { rules ['minLength' ]} ." )
31
+ issues .append (f"String ' { value } ' is shorter than the minimum length of { rules ['minLength' ]} ." )
32
32
if 'maxLength' in rules and len (value ) > rules ['maxLength' ]:
33
- issues .append (f"String is longer than the maximum length of { rules ['maxLength' ]} ." )
33
+ issues .append (f"String ' { value } ' is longer than the maximum length of { rules ['maxLength' ]} ." )
34
34
if 'pattern' in rules and not re .match (rules ['pattern' ], value ):
35
- issues .append (f"String does not match the required pattern: { rules ['pattern' ]} ." )
35
+ issues .append (f"String ' { value } ' does not match the required pattern: { rules ['pattern' ]} ." )
36
36
if 'enum' in rules and value not in rules ['enum' ]:
37
- issues .append (f"String is not one of the permitted values in the enumeration." )
37
+ allowed = ", " .join (rules ['enum' ])
38
+ issues .append (f"String '{ value } ' is not one of the allowed values in the enumeration: { allowed } " )
38
39
if 'format' in rules :
39
40
# todo: pre-compile regexes
40
41
if rules ['format' ] == 'email' and not re .match (r"[^@]+@[^@]+\.[^@]+" , value ):
41
- issues .append ("String is not a valid email." )
42
+ issues .append (f "String ' { value } ' is not a valid email address ." )
42
43
if rules ['format' ] == 'uri' and not urlparse (value ).scheme :
43
- issues .append ("String is not a valid URI." )
44
+ issues .append (f "String ' { value } ' is not a valid URI." )
44
45
if rules ['format' ] == 'uuid' and not re .match (r"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\Z" , value ):
45
- issues .append ("String is not a valid UUID." )
46
+ issues .append (f "String ' { value } ' is not a valid UUID." )
46
47
return issues
47
48
48
49
# Numerical validation
49
50
def validate_numerical (value , rules ):
50
51
issues = []
51
52
if 'minimum' in rules and value < rules ['minimum' ]:
52
- issues .append (f"Value is less than the minimum allowed value of { rules ['minimum' ]} ." )
53
+ issues .append (f"Value { value } is less than the minimum allowed value of { rules ['minimum' ]} ." )
53
54
if 'maximum' in rules and value > rules ['maximum' ]:
54
- issues .append (f"Value is greater than the maximum allowed value of { rules ['maximum' ]} ." )
55
+ issues .append (f"Value { value } is greater than the maximum allowed value of { rules ['maximum' ]} ." )
55
56
if 'exclusiveMinimum' in rules and value <= rules ['exclusiveMinimum' ]:
56
- issues .append (f"Value is less than or equal to the exclusive minimum value of { rules ['exclusiveMinimum' ]} ." )
57
+ issues .append (f"Value { value } is less than or equal to the exclusive minimum value of { rules ['exclusiveMinimum' ]} ." )
57
58
if 'exclusiveMaximum' in rules and value >= rules ['exclusiveMaximum' ]:
58
- issues .append (f"Value is greater than or equal to the exclusive maximum value of { rules ['exclusiveMaximum' ]} ." )
59
+ issues .append (f"Value { value } is greater than or equal to the exclusive maximum value of { rules ['exclusiveMaximum' ]} ." )
59
60
if 'enum' in rules and value not in rules ['enum' ]:
60
- issues .append ("Value is not one of the permitted values in the enumeration." )
61
+ allowed = ", " .join (map (str , rules ['enum' ]))
62
+ issues .append (f"String '{ value } ' is not one of the allowed values in the enumeration: { allowed } " )
61
63
return issues
62
64
63
65
# Array validation
0 commit comments