Skip to content

feat: add per-model endpoint export control (export_endpoint) + standalone export routes - #48

Merged
borhanst merged 15 commits into
mainfrom
feat/export-endpoint-control
Aug 19, 2026
Merged

feat: add per-model endpoint export control (export_endpoint) + standalone export routes#48
borhanst merged 15 commits into
mainfrom
feat/export-endpoint-control

Conversation

@borhanst

Copy link
Copy Markdown
Owner

Closes #47

Summary

Adds per-model control over which routers get auto-built/exported to Swagger, plus standalone router export helpers that need no admin.register().

ModelAdmin.export_endpoint: str | None = None

Value Admin (HTML) router JSON API router
None built built
"html" built skipped
"api" skipped built

Admin HTML model routes are now all include_in_schema=False (search, export/, import/, validate-field, inline-edit, actions, sort, autocomplete, /{id}/field) so only JSON API routes appear in /openapi.json.

Models with export_endpoint = "api" are also hidden from the sidebar and topbar search suggestions.

Standalone export (no admin.register() required)

class ProductAdmin(ModelAdmin):
    export_endpoint = "api"

app.include_router(ProductAdmin().export_api_route(Product))
app.include_router(ProductAdmin().export_admin_route(Product), prefix="/admin")
  • export_api_route(model, prefix="") — JSON CRUD router (appears in Swagger)
  • export_admin_route(model, prefix="") — HTML admin router (hidden from Swagger)

Both build via build_registered_model() and never write to the singleton registry.

Changes

  • fastapi_admin_kit/modeladmin.pyexport_endpoint + export_api_route/export_admin_route
  • fastapi_admin_kit/registry/core.py — extract build_registered_model() from AdminRegistry.register
  • fastapi_admin_kit/api/crud.py — new build_api_router_for_model(); build_api_router skips export_endpoint == "html"
  • fastapi_admin_kit/router.pybuild_model_router skips export_endpoint == "api"; include_in_schema=False on leaking HTML routes
  • fastapi_admin_kit/admin/core.py, admin/admin_router.py — skip API-only models
  • fastapi_admin_kit/nav.py, api/search.py — hide API-only models from sidebar/suggestions
  • Docs: docs/guide/json-api.md, docs/guide/model-registration.md
  • Tests: tests/test_export_endpoint.py (7 tests)

Acceptance criteria

  • None → both HTML + API routers built; only API routes in /openapi.json
  • "api" → API routes present, no /admin/... model routes in OpenAPI ✓
  • "html" → admin routes present, no /api/... model routes ✓
  • Standalone export_api_route(Product) / export_admin_route(Product) work without admin.register

Full test suite: 722 passed (1 pre-existing unrelated failure in test_search.py::TestM2MSave, verified failing on the base commit too).

…CreateView and EditView for improved validation handling
…egression tests for direct permission removal
…estamps and update query provider for ordering support
…ndalone router export

Add ModelAdmin.export_endpoint (None / "html" / "api") to control which
routers are auto-built per model, plus standalone export_api_route /
export_admin_route helpers that build routers without admin.register().

Admin HTML routes (search, export, import, validate-field, inline-edit,
actions, sort, autocomplete, field) are now hidden from /openapi.json;
only JSON API routes appear in the schema.
@borhanst
borhanst merged commit 862746a into main Aug 19, 2026
3 checks passed
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 per-model endpoint export control (export_endpoint) + standalone export_api_route/export_admin_route

1 participant