def find_route(self, decorated_controller: "DecoratedController"): reference = decorated_controller.reference for route in self.app.url_map.iter_rules(): if route.endpoint not in self.app.view_functions: continue route_callback = self.app.view_functions[route.endpoint] route_token = getattr(route_callback, DECORATION_ATTRIBUTE_NAME, None) match_with_wrapper = route_callback == reference.wrapper match_with_wrapped = route_callback == reference.wrapped match_with_token = route_token == reference.token # FIXME - G.M - 2017-12-04 - return list instead of one method # This fix, return only 1 allowed method, change this when # RouteRepresentation is adapted to return multiples methods. method = [ x for x in route.methods if x not in ["OPTIONS", "HEAD"] ][0] if match_with_wrapper or match_with_wrapped or match_with_token: return RouteRepresentation( rule=self.get_swagger_path(route.rule), method=method, original_route_object=route, )
def find_route( self, decorated_controller: DecoratedController) -> RouteRepresentation: if not len(self.app.router.routes()): raise NoRoutesException("There is no routes in your aiohttp app") reference = decorated_controller.reference for route in self.app.router.routes(): route_token = getattr(route.handler, DECORATION_ATTRIBUTE_NAME, None) match_with_wrapper = route.handler == reference.wrapper match_with_wrapped = route.handler == reference.wrapped match_with_token = route_token == reference.token # TODO BS 2018-07-27: token is set in HEAD view to, must solve this # case if (not match_with_wrapper and not match_with_wrapped and match_with_token and route.method.lower() == "head"): continue if match_with_wrapper or match_with_wrapped or match_with_token: return RouteRepresentation( rule=self.get_swagger_path(route.resource.canonical), method=route.method.lower(), original_route_object=route, ) # TODO BS 20171010: Raise exception or print error ? see #10 raise RouteNotFound( 'Decorated route "{}" was not found in aiohttp routes'.format( decorated_controller.name))