feat: add @endpoint decorator for custom ModelAdmin FastAPI routes - #53
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #49
Summary
Implements issue #49: add an
@endpointdecorator forModelAdminclasses that registers arbitrary FastAPI routes on a model's admin router, with fulladd_api_route()configuration support.Changes
fastapi_admin_kit/admin/decorators.py— newEndpointOptionsdataclass +endpoint()decorator. Stores config on the method as_admin_endpoint(mirrors the existing@column/@actionpattern).fastapi_admin_kit/router.py—build_model_router()auto-discovers_admin_endpointmethods and registers them viarouter.add_api_route(). Routes are registered before the/{id}catch-all so paths like/health-checkare never swallowed by the edit route. An untypedrequestparameter is injected as the FastAPIRequest(matching the documented usageasync def health_check(self, request)).permission="view"adds arequire_permission(<model>, <permission>)dependency; arbitrarydependencies=[Depends(...)]are also supported.endpointexported fromfastapi_admin_kitand exposed asModelAdmin.endpoint./<model_name>/<path>(e.g./admin/products/health-check)./{id}, untyped/typedrequest, query params, POST methods, RBAC denial, and OpenAPI docs.docs/guide/model-registration.mdanddocs/guide/features.mdupdated.Example
Verification
ruff checkpassespytest— 846 passed, 3 skipped (full suite)