From f3bd35b832b13fa44ef2228b5ed6bf136f65ef2e Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 24 Nov 2025 12:26:10 -0500 Subject: [PATCH] Filter API docs to only show /api endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add custom OpenAPI schema generation to filter documentation to only include routes starting with /api/. This keeps the API docs clean and focused on the actual API endpoints without cluttering them with web page routes. The /api/docs will now only show: - /api/search - /api/verse-of-the-day - /api/verse/{book}/{chapter}/{verse} - /api/verse-range/{book}/{chapter}/{start}/{end} 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- kjvstudy_org/server.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kjvstudy_org/server.py b/kjvstudy_org/server.py index ec4f739..d674c24 100644 --- a/kjvstudy_org/server.py +++ b/kjvstudy_org/server.py @@ -691,6 +691,27 @@ app = FastAPI( ) +# Custom OpenAPI schema to only include /api routes +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + + openapi_schema = app.openapi() + + # Filter paths to only include /api routes + filtered_paths = { + path: path_item + for path, path_item in openapi_schema["paths"].items() + if path.startswith("/api/") + } + + openapi_schema["paths"] = filtered_paths + app.openapi_schema = openapi_schema + return app.openapi_schema + +app.openapi = custom_openapi + + # Caching middleware for performance optimization class CacheControlMiddleware(BaseHTTPMiddleware): """Add cache control headers to responses for better performance"""