from typing import TYPE_CHECKING, Any from src.api_utils.middleware import ApiErrorMiddleware, LoggingMiddleware, MatchInfoMiddleware, \ SchemaValidationMiddleware, ServerErrorMiddleware from src.api_utils.router import Router from src.api_utils.spec import LambdaAPISpec, LambdaSpecPlugin from src.config import DEBUG from src.core.routes import routes as core_routes from src.middlewares import AuthMiddleware, CORSMiddleware from src.playlist_sync.routes import routes as playlist_sync_routes from src.service_account.routes import routes as service_account_routes if TYPE_CHECKING: from src.logger import BoundLogger def api_gateway_handler(event: dict, logger: "BoundLogger") -> dict[str, Any]: routes = list(core_routes + playlist_sync_routes + service_account_routes) api_spec = LambdaAPISpec( routes=routes, title="playlist sync API", version="1.0.0", openapi_version="3.0.2", plugins=[LambdaSpecPlugin()], components={ "securitySchemes": { "apiKey": { "type": "http", "description": "For example: test", "scheme": "bearer", "bearerFormat": "JWT", } } }, security=[{"apiKey": []}], ) routes.append(api_spec.get_spec_route()) router = Router( routes, middlewares=( LoggingMiddleware, CORSMiddleware, ServerErrorMiddleware, ApiErrorMiddleware, SchemaValidationMiddleware, MatchInfoMiddleware, AuthMiddleware, ), logger=logger, debug=DEBUG, ) return router.handle_event(event)