Skip to content

feat: add @endpoint decorator for custom ModelAdmin FastAPI routes - #53

Merged
borhanst merged 1 commit into
mainfrom
feat/endpoint-decorator
Aug 20, 2026
Merged

feat: add @endpoint decorator for custom ModelAdmin FastAPI routes#53
borhanst merged 1 commit into
mainfrom
feat/endpoint-decorator

Conversation

@borhanst

@borhanst borhanst commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Closes #49

Summary

Implements issue #49: add an @endpoint decorator for ModelAdmin classes that registers arbitrary FastAPI routes on a model's admin router, with full add_api_route() configuration support.

Changes

  • fastapi_admin_kit/admin/decorators.py — new EndpointOptions dataclass + endpoint() decorator. Stores config on the method as _admin_endpoint (mirrors the existing @column / @action pattern).
  • fastapi_admin_kit/router.pybuild_model_router() auto-discovers _admin_endpoint methods and registers them via router.add_api_route(). Routes are registered before the /{id} catch-all so paths like /health-check are never swallowed by the edit route. An untyped request parameter is injected as the FastAPI Request (matching the documented usage async def health_check(self, request)).
  • RBACpermission="view" adds a require_permission(<model>, <permission>) dependency; arbitrary dependencies=[Depends(...)] are also supported.
  • Exportsendpoint exported from fastapi_admin_kit and exposed as ModelAdmin.endpoint.
  • Pathing — endpoints are served under /<model_name>/<path> (e.g. /admin/products/health-check).
  • Tests — 16 tests covering metadata, registration, ordering vs. /{id}, untyped/typed request, query params, POST methods, RBAC denial, and OpenAPI docs.
  • Docsdocs/guide/model-registration.md and docs/guide/features.md updated.

Example

from fastapi_admin_kit import endpoint

@admin.register(Product)
class ProductAdmin(ModelAdmin):
    @endpoint(
        path="/health-check",
        methods=["GET"],
        tags=["monitoring"],
        description="Health check endpoint",
        permission="view",
    )
    async def health_check(self, request):
        return {"status": "healthy"}

Verification

  • ruff check passes
  • pytest — 846 passed, 3 skipped (full suite)

Implements issue #49. New @endpoint() decorator registers arbitrary
FastAPI routes on registered models' admin router via add_api_route().

- EndpointOptions dataclass + endpoint() decorator in admin/decorators.py
- build_model_router() auto-discovers _admin_endpoint methods and
  registers routes before the /{id} catch-all
- Supports path, methods, tags, description, name, dependencies,
  status_code, response_model, summary, response_description, permission
- permission integrates with existing RBAC (require_permission)
- Untyped 'request' params are injected as Request automatically
- Endpoint routes served under /<model_name>/<path>
- Exported from package root and exposed on ModelAdmin
- Docs + 16 tests
@borhanst
borhanst merged commit 8851023 into main Aug 20, 2026
3 checks passed
@borhanst
borhanst deleted the feat/endpoint-decorator branch August 20, 2026 06:36
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.

Add @endpoint decorator for ModelAdmin custom FastAPI routes

1 participant