Skip to content

[FastAPI] Add route resolver #111

Description

@theDakshJaitly

Target branch: main

Dependency

The Python code-graph extractor was merged in #103 and is available on main.
This issue is not blocked by another language extractor.

Goal

Add a bounded FastAPI framework resolver that connects decorator-defined HTTP
routes to their endpoint functions.

The initial implementation should cover statically recognizable routes without
evaluating application code or attempting to reconstruct the complete runtime
router.

Scope

  • Detect FastAPI from declared project dependencies such as pyproject.toml
    or requirements files.
  • Recognize literal route decorators including:
    • @app.get(), @app.post(), @app.put(), @app.patch()
    • @app.delete(), @app.options(), @app.head()
    • Equivalent decorators on APIRouter instances such as @router.get()
  • Support both synchronous and asynchronous endpoint functions.
  • Emit one stable route node for each recognized HTTP method and literal path.
  • Emit a function_ref from the route node to the decorated endpoint.
  • Resolve the reference only when the matching same-file function or method is
    unambiguous.
  • Preserve parameterized paths such as /users/{user_id}.
  • Leave missing or ambiguous handlers unresolved rather than guessing.

Required changes

  • Add src/graph/resolution/frameworks/fastapi.ts implementing
    FrameworkResolver.
  • Register and export it from
    src/graph/resolution/frameworks/index.ts.
  • Add a minimal FastAPI fixture under
    src/graph/__tests__/fixtures/.
  • Add focused detection, extraction, resolution, and ambiguity tests.

Acceptance criteria

  • Positive and negative FastAPI detection are tested.
  • Both FastAPI application and APIRouter decorators are covered.
  • Tests cover multiple HTTP methods and a parameterized path.
  • Both def and async def endpoints are covered.
  • Multiple decorators on one endpoint produce the expected route nodes.
  • Route nodes use stable IDs and Python as their language.
  • Same-file endpoints resolve only when unambiguous.
  • Missing and ambiguous handlers remain unresolved.
  • The resolver is registered in the framework registry.
  • npm run typecheck, npm test, and npm run build pass.
  • No identity, reconciliation, schema, or drift-semantics changes are included.

Out of scope

  • Composing prefixes across include_router() calls.
  • Runtime dependency injection or middleware analysis.
  • WebSocket routes, mounted applications, and event handlers.
  • Dynamic or computed route paths.
  • Evaluating Python modules or importing the application.

Contributor references

Contributor workflow

git switch main
git pull
git switch -c feat/fastapi-route-resolver

Open the pull request with main as the base branch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-graphWork related to the AST and Tree-sitter code graphenhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions