Closed vrslev closed 1 month ago
Here's the week-old patch I made into inner source package:
From 70bc3a5b1fb3246cb92994ed2fecf39d99f9a90e Mon Sep 17 00:00:00 2001
From: Lev
Date: Fri, 11 Oct 2024 11:53:25 +0300
Subject: [PATCH] Exclude `/health` and `/readiness` from OpenAPI schema
---
health_checks/fastapi_healthcheck.py | 2 +-
health_checks/litestar_healthcheck.py | 4 +++-
health_checks/readiness_checks/fastapi_readiness_check.py | 2 +-
health_checks/readiness_checks/litestar_readiness_check.py | 1 +
4 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/health_checks/fastapi_healthcheck.py b/health_checks/fastapi_healthcheck.py
index ceec49d..eb31b26 100644
--- a/health_checks/fastapi_healthcheck.py
+++ b/health_checks/fastapi_healthcheck.py
@@ -11,7 +11,7 @@ def build_fastapi_health_check_router(
health_check: HealthCheck,
health_check_endpoint: str = "/health/",
) -> APIRouter:
- fastapi_router: typing.Final = APIRouter(tags=["probes"])
+ fastapi_router: typing.Final = APIRouter(tags=["probes"], include_in_schema=False)
@fastapi_router.get(health_check_endpoint)
async def health_check_handler() -> JSONResponse:
diff --git a/health_checks/litestar_healthcheck.py b/health_checks/litestar_healthcheck.py
index 6709fa4..db5e855 100644
--- a/health_checks/litestar_healthcheck.py
+++ b/health_checks/litestar_healthcheck.py
@@ -18,4 +18,6 @@ def build_litestar_health_check_router(
return health_check_data
- return litestar.Router(path=health_check_endpoint, route_handlers=[health_check_handler], tags=["probes"])
+ return litestar.Router(
+ path=health_check_endpoint, route_handlers=[health_check_handler], tags=["probes"], include_in_schema=False
+ )
diff --git a/health_checks/readiness_checks/fastapi_readiness_check.py b/health_checks/readiness_checks/fastapi_readiness_check.py
index cc21509..9f2229a 100644
--- a/health_checks/readiness_checks/fastapi_readiness_check.py
+++ b/health_checks/readiness_checks/fastapi_readiness_check.py
@@ -10,7 +10,7 @@ def build_fastapi_readiness_check_router(
readiness_check: ReadinessHttpCheck,
readiness_check_endpoint: str = "/readiness/",
) -> APIRouter:
- fastapi_router: typing.Final = APIRouter(tags=["probes"])
+ fastapi_router: typing.Final = APIRouter(tags=["probes"], include_in_schema=False)
@fastapi_router.get(readiness_check_endpoint)
async def readiness_check_handler() -> JSONResponse:
diff --git a/health_checks/readiness_checks/litestar_readiness_check.py b/health_checks/readiness_checks/litestar_readiness_check.py
index d4fb439..110c15c 100644
--- a/health_checks/readiness_checks/litestar_readiness_check.py
+++ b/health_checks/readiness_checks/litestar_readiness_check.py
@@ -28,4 +28,5 @@ def build_litestar_readiness_check_router(
path=readiness_check_endpoint,
route_handlers=[readiness_check_handler],
tags=["probes"],
+ include_in_schema=False,
)
We should be able to configure if the route is included in schema, though
Similar to https://github.com/community-of-python/microbootstrap/pull/28