Skip to content

Commit 5e66f60

Browse files
authored
Merge pull request #35 from community-of-python/exclude-health-from-openapi-schema
Exclude `/health` route from OpenAPI schema by default, and allow to configure it
2 parents 680c4f7 + 5416354 commit 5e66f60

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ class YourSettings(BaseServiceSettings):
422422

423423
health_checks_enabled: bool = True
424424
health_checks_path: str = "/health/"
425+
health_checks_include_in_schema: bool = False
425426
```
426427

427428
Parameter descriptions:
@@ -430,6 +431,7 @@ Parameter descriptions:
430431
- `service_version` - Will be displayed in health check response.
431432
- `health_checks_enabled` - Must be True to enable health checks.
432433
- `health_checks_path` - Path for health check handler.
434+
- `health_checks_include_in_schema` - Must be True to include `health_checks_path` (`/health/`) in OpenAPI schema.
433435

434436
## Configuration
435437

@@ -558,7 +560,7 @@ application: litestar.Litestar = (
558560
## Advanced
559561
560562
If you miss some instrument, you can add your own.
561-
Essentialy, `Instrument` is just a class with some abstractmethods.
563+
Essentially, `Instrument` is just a class with some abstractmethods.
562564
Every instrument uses some config, so that's first thing, you have to define.
563565
564566
```python

microbootstrap/bootstrappers/fastapi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def get_config_type(cls) -> type[FastApiPrometheusConfig]:
122122
class FastApiHealthChecksInstrument(HealthChecksInstrument):
123123
def bootstrap_after(self, application: fastapi.FastAPI) -> fastapi.FastAPI:
124124
application.include_router(
125-
build_fastapi_health_check_router(self.health_check, self.instrument_config.health_checks_path),
125+
build_fastapi_health_check_router(
126+
health_check=self.health_check,
127+
health_check_endpoint=self.instrument_config.health_checks_path,
128+
include_in_schema=self.instrument_config.health_checks_include_in_schema,
129+
),
126130
)
127131
return application

microbootstrap/bootstrappers/litestar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
147147
return {
148148
"route_handlers": [
149149
build_litestar_health_check_router(
150-
self.health_check,
151-
self.instrument_config.health_checks_path,
150+
health_check=self.health_check,
151+
health_check_endpoint=self.instrument_config.health_checks_path,
152+
include_in_schema=self.instrument_config.health_checks_include_in_schema,
152153
),
153154
],
154155
}

microbootstrap/instruments/health_checks_instrument.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class HealthChecksConfig(BaseInstrumentConfig):
1111

1212
health_checks_enabled: bool = True
1313
health_checks_path: str = "/health/"
14+
health_checks_include_in_schema: bool = False
1415

1516

1617
class HealthChecksInstrument(Instrument[HealthChecksConfig]):

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fastapi = { version = "^0.111.0", optional = true }
6666
prometheus-fastapi-instrumentator = { version = "^6.1.0", optional = true }
6767
opentelemetry-instrumentation-fastapi = { version = "^0.46b0", optional = true }
6868
fastapi-offline-docs = { version = "^1.0.1", optional = true }
69-
health-checks = "^1.0.0"
69+
health-checks = "^1.1.0"
7070

7171
[tool.poetry.group.dev.dependencies]
7272
pytest = "^8.2.2"

0 commit comments

Comments
 (0)