Skip to content

Commit

Permalink
Fix incorrect deprecation replacement path (#67)
Browse files Browse the repository at this point in the history
This commit fixes the incorrect replacement path which is added to
depraceted operations when deprecation is enabled. The 'api' prefix
and the query params (apparent in the operation path) are added
to the replacement path.

Another small fix is a missing '-' in the input params.

Signed-off-by: Anton Obretenov <[email protected]>
  • Loading branch information
ToniO authored Nov 11, 2020
1 parent aa0f4f2 commit 54cf631
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/dictionary_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ def get_paths_inside_metamodel(service,
is_rest_navigation_checked = True

if has_rest_counterpart:
add_replacement_path(service, operation_id, request.lower(), path, replacement_dict)
url = path
if 'params' in service_dict[service].operations[operation_id].metadata[request].elements:
element_value = service_dict[service].operations[operation_id].metadata[request].elements['params']
params = "&".join(element_value.list_value)
url = path + '?' + params
add_replacement_path(service, operation_id, request.lower(), url, replacement_dict)

if not has_rest_counterpart or deprecate_rest or blacklist_utils.is_blacklisted_for_rest(service):
path_list.add(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/establish_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_input_params():
dest='fetch_auth_metadata',
help='retrieves authentication information from the authentication metadata service')
parser.add_argument(
'-ars'
'-ars',
'--auto-rest-services',
nargs='+',
default=[],
Expand Down
2 changes: 1 addition & 1 deletion lib/rest_endpoint/rest_deprecation_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def add_deprecation_information(self, path_obj, package_name, service_name):
# get concrete path and format accordingly
replacement_path = method_path_tuple[1]
replacement_path = replacement_path.replace("/", "~1")
replacement_path = api_file_name + "#/paths/" + replacement_path + "/" + method_path_tuple[0]
replacement_path = api_file_name + "#/paths/~1api" + replacement_path + "/" + method_path_tuple[0]

path_obj["x-vmw-deprecated"] = {"replacement": replacement_path}

12 changes: 9 additions & 3 deletions test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,12 @@ def test_get_paths_inside_metamodel(self):
rest_navigation_handler = RestNavigationHandler("")
element_value_mock = mock.Mock()
element_value_mock.string_value = 'mock_string_value'
element_params_value_mock = mock.Mock()
element_params_value_mock.list_value = ['action=filter', 'action=cancel']
element_info_mock = mock.Mock()
element_info_mock.elements = {
'path': element_value_mock
'path': element_value_mock,
'params': element_params_value_mock
}
operation_info_mock.metadata = {
'put': element_info_mock,
Expand All @@ -322,14 +325,17 @@ def test_get_paths_inside_metamodel(self):
operations = {
'mock-key-1': OperationInfo(metadata = {
'put' : ElementInfo(elemets = {
'path' : ElementValue(string_value = 'mock_string_value')
'path' : ElementValue(string_value = 'mock_string_value'),
'params'(
list_value = 'action=cancel'
)
}))
})
})
}
'''
path_list_expected = ['mock_string_value']
replacement_dict_expected = {service: {"mock-key-1": ("put", "mock_string_value")}}
replacement_dict_expected = {service: {"mock-key-1": ("put", "mock_string_value?action=filter&action=cancel")}}
replacement_dict_actual = {}
service_type_actual, path_list_actual = dict_processing.get_paths_inside_metamodel(service,
service_dict,
Expand Down
2 changes: 1 addition & 1 deletion test_rest_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_rest_deprecation(self):
self.rest_deprecation_handler.add_deprecation_information(path_obj, self.sample_package, self.sample_service)

self.assertEqual(path_obj['deprecated'], True)
self.assertEqual(path_obj["x-vmw-deprecated"]["replacement"], "api_vcenter.json#/paths/~1rest~1vcenter~1vm/get")
self.assertEqual(path_obj["x-vmw-deprecated"]["replacement"], "api_vcenter.json#/paths/~1api~1rest~1vcenter~1vm/get")


if __name__ == '__main__':
Expand Down

0 comments on commit 54cf631

Please sign in to comment.