code: def match_path_to_api_path(path_definitions, target_path, base_path='',
                             context=None):
      if context is None:
          context = {}
      assert isinstance(context, collections.Mapping)
      if target_path.startswith(base_path):
          normalized_target_path = re.sub(NORMALIZE_SLASH_REGEX, '/',
                                          target_path)
          matching_api_paths = list()
          matching_api_paths_regex = list()
          for p, v in path_definitions.items():
              full_path = re.sub(NORMALIZE_SLASH_REGEX, '/', base_path + p)
              r = path_to_regex(
                  api_path=full_path,
                  path_parameters=extract_path_parameters(v),
                  operation_parameters=extract_operation_parameters(v),
                  context=context,
              )
              if full_path == normalized_target_path:
                  matching_api_paths.append(p)
              elif r.match(normalized_target_path):
                  matching_api_paths_regex.\
                      append((p, r.match(normalized_target_path)))
          target_path = target_path[len(base_path):]
      else:
          matching_api_paths = []
          matching_api_paths_regex = []
      if not matching_api_paths and not matching_api_paths_regex:
          fstr = MESSAGES['path']['no_matching_paths_found'].format(target_path)
          raise LookupError(fstr)
      elif len(matching_api_paths) == 1:
          return matching_api_paths[0]
      elif len(matching_api_paths) > 1:
          raise MultiplePathsFound(
              MESSAGES['path']['multiple_paths_found'].format(
                  target_path, [v[0] for v in matching_api_paths],
              )
          )
      elif len(matching_api_paths_regex) == 1:
          return matching_api_paths_regex[0][0]
      elif len(matching_api_paths_regex) > 1:
          matches_by_path_size = collections.defaultdict(list)
          for path, match in matching_api_paths_regex:
              matches_by_path_size[len(path)].append(path)
          longest_match = max(matches_by_path_size.keys())
          if len(matches_by_path_size[longest_match]) == 1:
              return matches_by_path_size[longest_match][0]
          raise MultiplePathsFound(
              MESSAGES['path']['multiple_paths_found'].format(
                  target_path, [v[0] for v in matching_api_paths_regex],
              )
          )
      else:
          return matching_api_paths_regex[0][0]