def resolve_function_from_operation_id(self, operation_id): """ Invokes the function_resolver :type operation_id: str """ try: module_name, view_name, meth_name = operation_id.rsplit('.', 2) if operation_id and not view_name.endswith('View'): # If operation_id is not a view then assume it is a standard function return self.function_resolver(operation_id) mod = __import__(module_name, fromlist=[view_name]) view_cls = getattr(mod, view_name) # Find the class and instantiate it view = view_cls() func = getattr(view, meth_name) # Return the method function of the class return func except ImportError as e: msg = 'Cannot resolve operationId "{}"! Import error was "{}"'.format( operation_id, str(e)) raise ResolverError(msg, sys.exc_info()) except (AttributeError, ValueError) as e: raise ResolverError(str(e), sys.exc_info())
def resolve_function_from_operation_id(self, operation_id): """ Invokes the function_resolver :type operation_id: str """ try: return self.function_resolver(operation_id) except ImportError as e: msg = f'Cannot resolve operationId "{operation_id}"! Import error was "{str(e)}"' raise ResolverError(msg, sys.exc_info()) except (AttributeError, ValueError) as e: raise ResolverError(str(e), sys.exc_info())
def resolve_function_from_operation_id(self, operation_id): """ Invokes the function_resolver :type operation_id: str """ msg = 'Cannot resolve operationId "{}"!'.format(operation_id) try: return self.function_resolver(operation_id) except ImportError: import sys raise ResolverError(msg, sys.exc_info()) except AttributeError: raise ResolverError(msg)
def resolve_operation_id(self, operation): """ Resolves the operationId using REST semantics unless explicitly configured in the spec :type operation: connexion.operation.Operation """ # if no explicit operation_id # if no class, derive by how many are there # if otherwise, use classname.methodname # operationId = Resolver.resolve_operation_id(operation) spec = operation.operation operation_id = spec.get('operationId', '') x_router_controller = spec.get('x-swagger-router-controller') if x_router_controller: controller_name = x_router_controller else: if len(self.controllers) == 1: controller_name = next(iter(self.controllers.keys())) else: raise ResolverError("Could not determine which controller to use") if operation_id: method_name = operation_id else: method_name = ObjectResolver.method_from_operation(operation) # TODO: Split into own function return "{}.{}".format(controller_name, method_name)
def get_method_for_operation(self, operation): """ Return the method for the operation name. """ try: method = getattr(self, operation) except AttributeError: raise ResolverError("Controller {controller_type} has no operation '{method}'" .format(controller_type=self.__class__.__name__, method=operation)) else: return method
def resolve_function_from_operation_id(self, operation, operation_id): """ Invokes the function_resolver :type operation_id: str """ logging.debug(operation_id) try: module_name, view_name, meth_name = operation_id.rsplit('.', 2) if operation.operation_id and not view_name.endswith('View'): return self.function_resolver(operation_id) mod = __import__(module_name, fromlist=[view_name]) view_cls = getattr(mod, view_name) view = view_cls() func = getattr(view, meth_name) return func except ImportError as e: msg = 'Cannot resolve operationId "{}"! Import error was "{}"'.format(operation_id, str(e)) raise ResolverError(msg, sys.exc_info()) except (AttributeError, ValueError) as e: raise ResolverError(str(e), sys.exc_info())