@@ -775,24 +775,20 @@ impl ValidationEngine {
775775
776776 // Cardinality warnings.
777777 for ( ( var, attr_name) , count) in & attr_counts {
778- if let Some ( owner_type) = env. get_type ( var) {
779- let owned = schema. get_all_owned_attributes ( owner_type) ;
780- if let Some ( attr) = owned. iter ( ) . find ( |a| a. name == * attr_name) {
781- if let Some ( ref card) = attr. cardinality {
782- if let Some ( max) = card. max {
783- if * count as u32 > max {
784- errors. push ( warning (
785- "CARDINALITY_EXCEEDED" ,
786- format ! (
787- "Inserting {} values for '{}.{}' but @card allows max {}" ,
788- count, owner_type, attr_name, max
789- ) ,
790- path,
791- ) ) ;
792- }
793- }
794- }
795- }
778+ if let Some ( owner_type) = env. get_type ( var)
779+ && let Some ( attr) = schema. get_all_owned_attributes ( owner_type) . iter ( ) . find ( |a| a. name == * attr_name)
780+ && let Some ( ref card) = attr. cardinality
781+ && let Some ( max) = card. max
782+ && * count as u32 > max
783+ {
784+ errors. push ( warning (
785+ "CARDINALITY_EXCEEDED" ,
786+ format ! (
787+ "Inserting {} values for '{}.{}' but @card allows max {}" ,
788+ count, owner_type, attr_name, max
789+ ) ,
790+ path,
791+ ) ) ;
796792 }
797793 }
798794 }
@@ -845,19 +841,18 @@ impl ValidationEngine {
845841 self . validate_ownership ( owner_type, attr_name, schema, path, errors) ;
846842
847843 // Check value type compatibility.
848- if let Value :: Literal ( lit) = value {
849- if let Some ( attr_type) = schema. attributes . get ( attr_name) {
850- if !value_types_compatible ( & lit. value_type , & attr_type. value_type ) {
851- errors. push ( error (
852- "VALUE_TYPE_MISMATCH" ,
853- format ! (
854- "Attribute '{}' expects value type '{}', but got '{}'" ,
855- attr_name, attr_type. value_type, lit. value_type
856- ) ,
857- path,
858- ) ) ;
859- }
860- }
844+ if let Value :: Literal ( lit) = value
845+ && let Some ( attr_type) = schema. attributes . get ( attr_name)
846+ && !value_types_compatible ( & lit. value_type , & attr_type. value_type )
847+ {
848+ errors. push ( error (
849+ "VALUE_TYPE_MISMATCH" ,
850+ format ! (
851+ "Attribute '{}' expects value type '{}', but got '{}'" ,
852+ attr_name, attr_type. value_type, lit. value_type
853+ ) ,
854+ path,
855+ ) ) ;
861856 }
862857 }
863858
@@ -1040,13 +1035,13 @@ impl ValidationEngine {
10401035 let values = extract_values ( data, attr_name) ;
10411036 let mut errors = Vec :: new ( ) ;
10421037 for val in values {
1043- if let Some ( s) = val. as_str ( ) {
1044- if !compiled. is_match ( s) {
1045- let msg = custom_msg
1046- . map ( |m| m . to_string ( ) )
1047- . unwrap_or_else ( || format ! ( "'{}' value '{}' does not match required pattern" , attr_name , s ) ) ;
1048- errors . push ( error ( "RULE_REGEX_MISMATCH ", msg , path ) ) ;
1049- }
1038+ if let Some ( s) = val. as_str ( )
1039+ && !compiled. is_match ( s)
1040+ {
1041+ let msg = custom_msg
1042+ . map ( |m| m . to_string ( ) )
1043+ . unwrap_or_else ( || format ! ( "'{}' value '{}' does not match required pattern ", attr_name , s ) ) ;
1044+ errors . push ( error ( "RULE_REGEX_MISMATCH" , msg , path ) ) ;
10501045 }
10511046 }
10521047 errors
@@ -1065,21 +1060,21 @@ impl ValidationEngine {
10651060 let mut errors = Vec :: new ( ) ;
10661061 for val in values {
10671062 if let Some ( n) = val. as_f64 ( ) {
1068- if let Some ( lo) = min {
1069- if n < lo {
1070- let msg = custom_msg
1071- . map ( |m| m . to_string ( ) )
1072- . unwrap_or_else ( || format ! ( "'{}' value {} is below minimum {}" , attr_name , n , lo ) ) ;
1073- errors . push ( error ( "RULE_RANGE_VIOLATION ", msg , path ) ) ;
1074- }
1063+ if let Some ( lo) = min
1064+ && n < lo
1065+ {
1066+ let msg = custom_msg
1067+ . map ( |m| m . to_string ( ) )
1068+ . unwrap_or_else ( || format ! ( "'{}' value {} is below minimum {} ", attr_name , n , lo ) ) ;
1069+ errors . push ( error ( "RULE_RANGE_VIOLATION" , msg , path ) ) ;
10751070 }
1076- if let Some ( hi) = max {
1077- if n > hi {
1078- let msg = custom_msg
1079- . map ( |m| m . to_string ( ) )
1080- . unwrap_or_else ( || format ! ( "'{}' value {} is above maximum {}" , attr_name , n , hi ) ) ;
1081- errors . push ( error ( "RULE_RANGE_VIOLATION ", msg , path ) ) ;
1082- }
1071+ if let Some ( hi) = max
1072+ && n > hi
1073+ {
1074+ let msg = custom_msg
1075+ . map ( |m| m . to_string ( ) )
1076+ . unwrap_or_else ( || format ! ( "'{}' value {} is above maximum {} ", attr_name , n , hi ) ) ;
1077+ errors . push ( error ( "RULE_RANGE_VIOLATION" , msg , path ) ) ;
10831078 }
10841079 }
10851080 }
@@ -1128,13 +1123,13 @@ impl ValidationEngine {
11281123 . unwrap_or_else ( || format ! ( "'{}' has {} values, minimum is {}" , attr_name, count, min) ) ;
11291124 errors. push ( error ( "RULE_CARDINALITY_VIOLATION" , msg, path) ) ;
11301125 }
1131- if let Some ( mx) = max {
1132- if count > mx {
1133- let msg = custom_msg
1134- . map ( |m| m . to_string ( ) )
1135- . unwrap_or_else ( || format ! ( "'{}' has {} values, maximum is {}" , attr_name , count , mx ) ) ;
1136- errors . push ( error ( "RULE_CARDINALITY_VIOLATION ", msg , path ) ) ;
1137- }
1126+ if let Some ( mx) = max
1127+ && count > mx
1128+ {
1129+ let msg = custom_msg
1130+ . map ( |m| m . to_string ( ) )
1131+ . unwrap_or_else ( || format ! ( "'{}' has {} values, maximum is {} ", attr_name , count , mx ) ) ;
1132+ errors . push ( error ( "RULE_CARDINALITY_VIOLATION" , msg , path ) ) ;
11381133 }
11391134 errors
11401135 }
@@ -1153,21 +1148,21 @@ impl ValidationEngine {
11531148 for val in values {
11541149 if let Some ( s) = val. as_str ( ) {
11551150 let len = s. len ( ) as u32 ;
1156- if let Some ( lo) = min {
1157- if len < lo {
1158- let msg = custom_msg
1159- . map ( |m| m . to_string ( ) )
1160- . unwrap_or_else ( || format ! ( "'{}' value has length {}, minimum is {}" , attr_name , len , lo ) ) ;
1161- errors . push ( error ( "RULE_LENGTH_VIOLATION ", msg , path ) ) ;
1162- }
1151+ if let Some ( lo) = min
1152+ && len < lo
1153+ {
1154+ let msg = custom_msg
1155+ . map ( |m| m . to_string ( ) )
1156+ . unwrap_or_else ( || format ! ( "'{}' value has length {}, minimum is {} ", attr_name , len , lo ) ) ;
1157+ errors . push ( error ( "RULE_LENGTH_VIOLATION" , msg , path ) ) ;
11631158 }
1164- if let Some ( hi) = max {
1165- if len > hi {
1166- let msg = custom_msg
1167- . map ( |m| m . to_string ( ) )
1168- . unwrap_or_else ( || format ! ( "'{}' value has length {}, maximum is {}" , attr_name , len , hi ) ) ;
1169- errors . push ( error ( "RULE_LENGTH_VIOLATION ", msg , path ) ) ;
1170- }
1159+ if let Some ( hi) = max
1160+ && len > hi
1161+ {
1162+ let msg = custom_msg
1163+ . map ( |m| m . to_string ( ) )
1164+ . unwrap_or_else ( || format ! ( "'{}' value has length {}, maximum is {} ", attr_name , len , hi ) ) ;
1165+ errors . push ( error ( "RULE_LENGTH_VIOLATION" , msg , path ) ) ;
11711166 }
11721167 }
11731168 }
0 commit comments