Skip to content

Adopt FastAPI Annotated[] DI pattern across API layer #498

Description

@pavelzbornik

Problem

The API layer uses the legacy param: Type = Depends() pattern for dependency injection. SonarCloud flags 52 blocker-level code smells for this across the API layer.

The modern FastAPI pattern (since v0.95+) uses Annotated:

# Old pattern
async def endpoint(service: MyService = Depends()):

# New pattern
from typing import Annotated
async def endpoint(service: Annotated[MyService, Depends()]):

Affected Files

  • app/api/audio_api.py — 12 instances
  • app/api/audio_services_api.py — 20 instances
  • app/api/task_api.py — 3 instances
  • app/api/dependencies.py — dependency provider definitions

Tasks

  • Define reusable type aliases in app/api/dependencies.py (e.g., AudioService = Annotated[AudioService, Depends(get_audio_service)])
  • Update audio_api.py endpoints to use Annotated[]
  • Update audio_services_api.py endpoints to use Annotated[]
  • Update task_api.py endpoints to use Annotated[]
  • Run task check && task test to verify no regressions

Acceptance Criteria

  • All Depends() calls in API endpoints use Annotated[] pattern
  • SonarCloud blocker code smells resolved
  • All tests pass, coverage maintained >=80%

Activity

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

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions