Skip to content

refactor(apigateway): Add BaseRouter and duplicate route check #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 15, 2021
19 changes: 6 additions & 13 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import zlib
from abc import ABC, abstractmethod
from enum import Enum
from functools import partial, wraps
from functools import partial
from http import HTTPStatus
from typing import Any, Callable, Dict, List, Optional, Set, Union

Expand Down Expand Up @@ -669,7 +669,7 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
rule = prefix if rule == "/" else f"{prefix}{rule}"
route = (rule, *route[1:])

self.route(*route)(func())
self.route(*route)(func)


class Router(BaseRouter):
Expand All @@ -696,18 +696,11 @@ def route(
compress: bool = False,
cache_control: Optional[str] = None,
):
def actual_decorator(func: Callable):
@wraps(func)
def wrapper():
def inner_wrapper(**kwargs):
return func(**kwargs)

return inner_wrapper

def register_route(func: Callable):
if isinstance(method, (list, tuple)):
for item in method:
self.routes[(rule, item, cors, compress, cache_control)] = wrapper
self.routes[(rule, item, cors, compress, cache_control)] = func
else:
self.routes[(rule, method, cors, compress, cache_control)] = wrapper
self.routes[(rule, method, cors, compress, cache_control)] = func

return actual_decorator
return register_route