def schemaValidate(line_dict, schema_data): """ Consumes schema_data dict and validates data types and field specifications as mentioned in schema.json by invoking Validator() instance methods Returns a dictionary, error_dict that contains key, value pairs corresponding to the schema mismatches observed in each json record """ line_obj = Validator(line_dict) for key in schema_data['properties'].keys(): key_type = schema_data['properties'][key]['type'] if schema_data['properties'][ key]['is_required'] == "yes" and line_obj.line_dict.get( key, 'NA') == 'NA': line_obj.error_dict[key] = "Null Data Entry" continue if key_type == "string": line_obj.isVarchar( key, schema_data['properties'][key].get('field_len', None)) elif key_type == "int": line_obj.isDigit( key, schema_data['properties'][key].get('field_len', None)) elif key_type == "email": line_obj.isValidEmail(key) elif key_type == "datetime": line_obj.isDateTime(key, schema_data['properties'][key]['date_format']) elif key_type == "enum": line_obj.isValidEnum(key, schema_data['properties'][key]['enum_list']) else: pass if line_obj.error_dict.get('birth_date', 'NA') == 'NA' and line_obj.error_dict.get( 'created_at', 'NA') == 'NA': #run isEighteen check only if Birth_Date and created_at are valid and not null isEighteen(line_obj, line_obj.line_dict['birth_date'], line_obj.line_dict['created_at']) hasValidId(line_obj) return line_obj.error_dict