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.
This commit is contained in:
parent
21698203fe
commit
09560296aa
4 changed files with 34 additions and 13 deletions
|
|
@ -12,7 +12,7 @@ router = APIRouter(prefix="/api/meta", tags=["meta"])
|
|||
async def get_constants() -> ConstantsResponse:
|
||||
"""Get shared constants for frontend/backend synchronization."""
|
||||
return ConstantsResponse(
|
||||
permissions=[p.value for p in Permission],
|
||||
permissions=list(Permission),
|
||||
roles=[ROLE_ADMIN, ROLE_REGULAR],
|
||||
invite_statuses=[s.value for s in InviteStatus],
|
||||
invite_statuses=list(InviteStatus),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue