diff --git a/CHANGES.md b/CHANGES.md index 36c193fb..ba305f19 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,10 @@ - avoid future deprecation for pydantic.Field and use `json_schema_extra` instead of `openapi_examples` - use `orjson` based JSONResponse when available +### Added + +- add response model for `/_mgmt/health` endpoint + ## [5.2.0] - 2025-04-18 ### Fixed diff --git a/stac_fastapi/api/stac_fastapi/api/app.py b/stac_fastapi/api/stac_fastapi/api/app.py index 86800143..ed39c31a 100644 --- a/stac_fastapi/api/stac_fastapi/api/app.py +++ b/stac_fastapi/api/stac_fastapi/api/app.py @@ -21,6 +21,7 @@ CollectionUri, EmptyRequest, GeoJSONResponse, + HealthCheck, ItemCollectionUri, ItemUri, JSONResponse, @@ -397,12 +398,15 @@ async def ping(): mgmt_router.add_api_route( name="Health", path="/_mgmt/health", - response_model=Dict, + response_model=( + HealthCheck if self.settings.enable_response_models else None + ), responses={ 200: { "content": { MimeTypes.json.value: {}, }, + "model": HealthCheck, }, }, response_class=self.response_class, diff --git a/stac_fastapi/api/stac_fastapi/api/models.py b/stac_fastapi/api/stac_fastapi/api/models.py index 581ec620..fc764efe 100644 --- a/stac_fastapi/api/stac_fastapi/api/models.py +++ b/stac_fastapi/api/stac_fastapi/api/models.py @@ -1,6 +1,6 @@ """Api request/response models.""" -from typing import List, Optional, Type, Union +from typing import List, Literal, Optional, Type, Union import attr from fastapi import Path, Query @@ -135,3 +135,9 @@ class JSONSchemaResponse(JSONResponse): """JSON with custom, vendor content-type.""" media_type = "application/schema+json" + + +class HealthCheck(BaseModel, extra="allow"): + """health check response model.""" + + status: Literal["UP", "DOWN"]