arbret/backend/routes/meta.py
counterweight 09560296aa
refactor: derive Permission type from generated OpenAPI schema
Issue #3: The frontend Permission enum was manually duplicated from
the backend. While full generation isn't practical, this change
ties the frontend constants to the generated OpenAPI types for
compile-time validation.

Changes:
- Update ConstantsResponse schema to use actual Permission/InviteStatus
  enums (enables OpenAPI to include enum values)
- Import enums in schemas.py (no circular dependency issue)
- Update auth-context.tsx to derive PermissionType from generated schema
- Update meta route to return enum instances instead of string values
- Permission values are now type-checked against the OpenAPI schema

If a permission is added to the backend but not to the frontend's
Permission object, TypeScript will fail to compile. This provides
a safety net without requiring a complex build-time generation step.
2025-12-21 23:55:47 +01:00

18 lines
577 B
Python

"""Meta endpoints for shared constants."""
from fastapi import APIRouter
from models import ROLE_ADMIN, ROLE_REGULAR, InviteStatus, Permission
from schemas import ConstantsResponse
router = APIRouter(prefix="/api/meta", tags=["meta"])
@router.get("/constants", response_model=ConstantsResponse)
async def get_constants() -> ConstantsResponse:
"""Get shared constants for frontend/backend synchronization."""
return ConstantsResponse(
permissions=list(Permission),
roles=[ROLE_ADMIN, ROLE_REGULAR],
invite_statuses=list(InviteStatus),
)