Skip to content

Commit

Permalink
[VAPI-4801] Fix deprecation links in the api-explorer
Browse files Browse the repository at this point in the history
This change fixes the following three issues:
1. /api/session is not linked to /rest/com/vmware/cis/session (due to the lack
   of /cis in the new representation)
2. vmw-task=true (i.e. @TaskOnly) operations are not linked properly
3. the new token-exchange is not linked to the old one (there is no metadata
   for that link)

It also fixes the filename used in the deprecation path by removing the
'api_' prefix. This doesn't affect the api-explorer in any way.

Testing done: switched the 3 affected files on a deployment and verified
that operations are now properly linked.

Signed-off-by: Anton Obretenov <[email protected]>
  • Loading branch information
dmitankin authored and Anton Obretenov committed Jan 5, 2021
1 parent 54cf631 commit 12466b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
10 changes: 8 additions & 2 deletions lib/dictionary_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def add_service_urls_using_metamodel(
for path in path_list:
service_urls_map[path] = (service, '/api')
package_name = path.split('/')[1]
# special handling for /api/sesion
if package_name == 'session':
package_name = 'cis'
pack_arr = package_dict_api.get(package_name, [])
if pack_arr == []:
package_dict_api[package_name] = pack_arr
Expand Down Expand Up @@ -210,10 +213,13 @@ def get_paths_inside_metamodel(service,

if has_rest_counterpart:
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']
elems = service_dict[service].operations[operation_id].metadata[request].elements
if 'params' in elems:
element_value = elems['params']
params = "&".join(element_value.list_value)
url = path + '?' + params
if operation_id.endswith('$task'):
url = utils.add_query_param(url, 'vmw-task=true')
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):
Expand Down
28 changes: 17 additions & 11 deletions lib/rest_endpoint/rest_deprecation_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ def __init__(self, replacement_dict):
self.replacement_dict = replacement_dict

def add_deprecation_information(self, path_obj, package_name, service_name):
replacement_path = "<unknown>"
path_obj["deprecated"] = True

# construct file name
api_file_name = "api_" + package_name + ".json"

method = None
new_path = None
# Could be a more intelligent resolution - guessing based on key words?
operation_map = self.replacement_dict.get(service_name)
if operation_map is not None and "operationId" in path_obj:
method_path_tuple = operation_map.get(path_obj["operationId"])
if method_path_tuple is not None:
# get concrete path and format accordingly
replacement_path = method_path_tuple[1]
replacement_path = replacement_path.replace("/", "~1")
replacement_path = api_file_name + "#/paths/~1api" + replacement_path + "/" + method_path_tuple[0]
method = method_path_tuple[0]
new_path = method_path_tuple[1]

path_obj["x-vmw-deprecated"] = {"replacement": replacement_path}
RestDeprecationHandler.add_deprecation_information_raw(path_obj, package_name, method, new_path)

@staticmethod
def add_deprecation_information_raw(path_obj, package_name, method, new_path):
replacement_path = "<unknown>"
path_obj["deprecated"] = True

# construct file name
api_file_name = package_name + ".json"

if method is not None and new_path is not None:
replacement_path = api_file_name + "#/paths/~1api" + new_path.replace("/", "~1") + "/" + method

path_obj["x-vmw-deprecated"] = {"replacement": replacement_path}
8 changes: 6 additions & 2 deletions lib/rest_endpoint/rest_metadata_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lib import utils
from lib.metadata_processor import MetadataProcessor
from .oas3.rest_metamodel2openapi import RestMetamodel2Openapi
from .rest_deprecation_handler import RestDeprecationHandler
from .swagger2.rest_metamodel2swagger import RestMetamodel2Swagger

swagg = RestMetamodel2Swagger()
Expand Down Expand Up @@ -82,8 +83,11 @@ def get_path_and_type_dicts(
http_error_map,
show_unreleased_apis)

if deprecation_handler is not None and service_end_point == "/deprecated":
deprecation_handler.add_deprecation_information(path, package_name, service_name)
if deprecation_handler is not None:
if operation_id == 'exchange' and service_name == 'com.vmware.vcenter.tokenservice.token_exchange':
RestDeprecationHandler.add_deprecation_information_raw(path, package_name, 'post', '/vcenter/authentication/token')
elif service_end_point == "/deprecated":
deprecation_handler.add_deprecation_information(path, package_name, service_name)
path_list.append(path)
continue
# use rest navigation service to get the REST mappings for a
Expand Down

0 comments on commit 12466b6

Please sign in to comment.