Skip to content

Commit

Permalink
Merge pull request usdot-jpo-ode#40 from usdot-jpo-ode/arrays-additio…
Browse files Browse the repository at this point in the history
…nal-support

Resolved issue with array not being able to validate varied formats o…
  • Loading branch information
drewjj authored Sep 18, 2019
2 parents da00d0c + 4a7120d commit c1c57ed
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions odevalidator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@ def populate_list_validations(self, keys, data, path, path_init, indexes): # Re
path = path + '{0}'
keys = self.set_keys(keys)
indexes.append('{0}')
self.populate_list_validations(keys, data, path, path_init, indexes)
self.populate_list_validations(keys, data, path, path_init, copy.deepcopy(indexes))
if type(data) != list:
keys = self.set_keys(keys)
indexes.append('')
self.populate_list_validations(keys, data, path, path_init, indexes)
self.populate_list_validations(keys, data, path, path_init, copy.deepcopy(indexes))
else:
for i in (range(length)):
path_temp = path + '{' + str(i) + '}'
keys_temp = keys[1:]
data_temp = data[i]
indexes.append('{' + str(i) + '}')
self.populate_list_validations(keys_temp, data_temp, path_temp, path_init, indexes) # Recurcive functionality
self.populate_list_validations(keys_temp, data_temp, path_temp, path_init, copy.deepcopy(indexes)) # Recurcive functionality
indexes = indexes[:-1]
elif keys[0] in data:
try:
Expand All @@ -350,23 +350,23 @@ def populate_list_validations(self, keys, data, path, path_init, indexes): # Re
raise e
path = self.set_path(path, keys[0])
keys = self.set_keys(keys)
self.populate_list_validations(keys, data, path, path_init, indexes)
self.populate_list_validations(keys, data, path, path_init, copy.deepcopy(indexes))
elif keys[0].count('{') == 1: # Index of list hardcoded
index_begin = keys[0].index('{')
index_end = keys[0].index('}')
index = int(keys[0][(index_begin + 1):index_end])
if keys[0][:index_begin] not in data:
path = self.set_path(path, keys[0])
keys = self.set_keys(keys)
self.populate_list_validations(keys, '', path, path_init, indexes)
self.populate_list_validations(keys, '', path, path_init, copy.deepcopy(indexes))
elif type(data[keys[0][:index_begin]]) != list:
if data.get(keys[0][:index_begin]):
data = data[keys[0][:index_begin]]
else:
data = ''
path = self.set_path(path, keys[0][:index_begin])
keys = self.set_keys(keys)
self.populate_list_validations(keys, data, path, path_init, indexes)
self.populate_list_validations(keys, data, path, path_init, copy.deepcopy(indexes))
else:
if data.get(keys[0][:index_begin]):
try:
Expand All @@ -375,11 +375,11 @@ def populate_list_validations(self, keys, data, path, path_init, indexes): # Re
data = ''
path = self.set_path(path, keys[0])
keys = self.set_keys(keys)
self.populate_list_validations(keys, data, path, path_init, indexes)
self.populate_list_validations(keys, data, path, path_init, copy.deepcopy(indexes))
else: # key not found in data
path = self.set_path(path, keys[0])
keys = self.set_keys(keys)
self.populate_list_validations(keys, '', path, path_init, indexes)
self.populate_list_validations(keys, '', path, path_init, copy.deepcopy(indexes))

def set_path(self, path, key):
if not path:
Expand Down Expand Up @@ -411,7 +411,7 @@ def set_config_equals_value(self, path_init, path, indexes):
i = 0
while '.list' in new_path:
i = new_path.find('.list')
new_path = new_path[:i] + indexes[0] + new_path[(i+5):]
new_path = new_path[:i] + indexes.pop(0) + new_path[(i+5):]
new_equals_value = equals_value.replace(embedded_path, new_path)
config['EqualsValue'] = new_equals_value
return equals_value, config
Expand Down

0 comments on commit c1c57ed

Please sign in to comment.