Filter API docs to only show /api endpoints

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 <noreply@anthropic.com>
This commit is contained in:
2025-11-24 12:26:10 -05:00
parent 298bf16f54
commit f3bd35b832
+21
View File
@@ -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"""