Skip to content

Conversation

@alokemajumder
Copy link
Collaborator

Summary

Upgrades FastAPI to 0.124.0 and implements modern patterns for better documentation and type safety.

Dependencies Updated

Package Old New
FastAPI 0.115.4 0.124.0
Pydantic 2.9.2 2.10.3
Pydantic-settings 2.6.1 2.7.0
Uvicorn 0.32.0 0.32.1
Starlette 0.35.1 0.45.2
annotated-doc - 0.1.0 (new)

New Features Implemented

Annotated Type Hints with Doc

  • Dependencies use Annotated[Type, Doc("description")] for better OpenAPI docs
  • Created typed dependency aliases: DatabaseSession, RequiredAPIKey, CurrentUser
  • Enhanced parameter documentation in headers with examples

Enhanced Pydantic Models

  • Added json_schema_extra with examples for all request/response models
  • Implemented @computed_field for derived properties (is_complete, duration_seconds, total_pages)
  • Added validation constraints (ge, le) to numeric fields
  • Full Annotated[Type, Field(...), Doc(...)] pattern throughout

Improved OpenAPI Documentation

  • Added tag descriptions for endpoint grouping
  • Enhanced API description with markdown formatting (features, auth, rate limits)
  • Configured Swagger UI parameters (deepLinking, persistAuthorization, displayRequestDuration)
  • Added response schemas for error cases (400, 401, 429, 503)
  • Enabled separate_input_output_schemas for cleaner schema generation

Code Quality

  • Consistent use of status.HTTP_* constants
  • Better error responses with structured ErrorResponse model
  • Type hints throughout codebase

Files Changed

  • requirements.txt - Updated core dependencies
  • docker/requirements-stable.txt - Updated stable dependencies
  • api/dependencies.py - Typed dependency aliases with Doc
  • api/models/job.py - Enhanced Pydantic models with computed fields
  • api/routers/convert.py - Modern endpoint definitions with response schemas
  • api/main.py - Enhanced OpenAPI configuration

Test Plan

  • Docker compose config validates
  • Swagger UI loads with enhanced documentation
  • API endpoints respond correctly
  • Type hints work with IDE autocomplete

## Dependencies Updated
- FastAPI: 0.115.4 → 0.124.0
- Pydantic: 2.9.2 → 2.10.3
- Pydantic-settings: 2.6.1 → 2.7.0
- Uvicorn: 0.32.0 → 0.32.1
- Starlette: → 0.45.2
- Added: annotated-doc for Doc type hints

## New Features Implemented

### Annotated Type Hints with Doc
- Dependencies use `Annotated[Type, Doc("description")]` for better docs
- Created typed dependency aliases: `DatabaseSession`, `RequiredAPIKey`
- Enhanced parameter documentation in headers

### Enhanced Pydantic Models
- Added `json_schema_extra` with examples for all request/response models
- Implemented `@computed_field` for derived properties (is_complete, duration_seconds)
- Added validation constraints (ge, le) to numeric fields
- Full `Annotated[Type, Field(...), Doc(...)]` pattern

### Improved OpenAPI Documentation
- Added tag descriptions for endpoint grouping
- Enhanced API description with markdown formatting
- Configured Swagger UI parameters (deepLinking, persistAuthorization)
- Added response schemas for error cases (400, 401, 429, 503)
- Enabled `separate_input_output_schemas` for cleaner schema generation

### Code Quality
- Consistent use of `status.HTTP_*` constants
- Better error responses with structured error objects
- Type hints throughout codebase
@gensecai-dev gensecai-dev merged commit 0a68186 into main Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants