from __future__ import annotations from hashlib import sha256 from app.modules.rag.indexing.code.entrypoints.registry import Entrypoint class FastApiEntrypointDetector: _METHODS = {"get", "post", "put", "patch", "delete"} def detect(self, *, path: str, symbols: list) -> list[Entrypoint]: items: list[Entrypoint] = [] for symbol in symbols: decorators = symbol.decorators or [] for decorator in decorators: name = decorator.lower() tail = name.split(".")[-1] if tail not in self._METHODS and ".route" not in name: continue route = decorator.split("(")[-1].rstrip(")") if "(" in decorator else decorator items.append( Entrypoint( entry_id=sha256(f"{path}|fastapi|{symbol.symbol_id}|{decorator}".encode("utf-8")).hexdigest(), entry_type="http", framework="fastapi", route_or_command=route, handler_symbol_id=symbol.symbol_id, path=path, start_line=symbol.start_line, end_line=symbol.end_line, metadata={"methods": [tail.upper()] if tail in self._METHODS else []}, ) ) return items