feat: add per-model endpoint export control (export_endpoint) + standalone export routes - #48
Merged
Merged
Conversation
…sion dependencies
…CreateView and EditView for improved validation handling
…ndling in query provider
…hance JSON parsing for notification data
…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.
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 #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 = NoneNone"html""api"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)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.py—export_endpoint+export_api_route/export_admin_routefastapi_admin_kit/registry/core.py— extractbuild_registered_model()fromAdminRegistry.registerfastapi_admin_kit/api/crud.py— newbuild_api_router_for_model();build_api_routerskipsexport_endpoint == "html"fastapi_admin_kit/router.py—build_model_routerskipsexport_endpoint == "api";include_in_schema=Falseon leaking HTML routesfastapi_admin_kit/admin/core.py,admin/admin_router.py— skip API-only modelsfastapi_admin_kit/nav.py,api/search.py— hide API-only models from sidebar/suggestionsdocs/guide/json-api.md,docs/guide/model-registration.mdtests/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 ✓export_api_route(Product)/export_admin_route(Product)work withoutadmin.register✓Full test suite: 722 passed (1 pre-existing unrelated failure in
test_search.py::TestM2MSave, verified failing on the base commit too).