From 54cf631512e69ca731a1fd5c0662b647833e7e2d Mon Sep 17 00:00:00 2001 From: ToniO Date: Wed, 11 Nov 2020 13:36:46 +0200 Subject: [PATCH] Fix incorrect deprecation replacement path (#67) 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 --- lib/dictionary_processing.py | 7 ++++++- lib/establish_connection.py | 2 +- lib/rest_endpoint/rest_deprecation_handler.py | 2 +- test_lib.py | 12 +++++++++--- test_rest_deprecation.py | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/dictionary_processing.py b/lib/dictionary_processing.py index 84eaa0e..3350b95 100644 --- a/lib/dictionary_processing.py +++ b/lib/dictionary_processing.py @@ -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) diff --git a/lib/establish_connection.py b/lib/establish_connection.py index 80ae5bc..8050478 100644 --- a/lib/establish_connection.py +++ b/lib/establish_connection.py @@ -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=[], diff --git a/lib/rest_endpoint/rest_deprecation_handler.py b/lib/rest_endpoint/rest_deprecation_handler.py index afdee07..5312bad 100644 --- a/lib/rest_endpoint/rest_deprecation_handler.py +++ b/lib/rest_endpoint/rest_deprecation_handler.py @@ -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} diff --git a/test_lib.py b/test_lib.py index 1d7dc91..e8ea5bb 100644 --- a/test_lib.py +++ b/test_lib.py @@ -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, @@ -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, diff --git a/test_rest_deprecation.py b/test_rest_deprecation.py index 6001eec..c99599a 100644 --- a/test_rest_deprecation.py +++ b/test_rest_deprecation.py @@ -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__':