Skip to content

Commit 3453507

Browse files
committed
Merge branch 'main' of https://github.com/stac-utils/stac-fastapi into HEAD
2 parents 096066c + fc44bf3 commit 3453507

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- avoid future deprecation for pydantic.Field and use `json_schema_extra` instead of `openapi_examples`
88
- use `orjson` based JSONResponse when available
9+
- changed from `AssertionError` to `HTTPException` for **bbox** parsing exceptions
10+
11+
### Added
12+
13+
- add response model for `/_mgmt/health` endpoint
914

1015
## [5.2.0] - 2025-04-18
1116

stac_fastapi/api/stac_fastapi/api/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
CollectionUri,
2222
EmptyRequest,
2323
GeoJSONResponse,
24+
HealthCheck,
2425
ItemCollectionUri,
2526
ItemUri,
2627
JSONResponse,
@@ -397,12 +398,15 @@ async def ping():
397398
mgmt_router.add_api_route(
398399
name="Health",
399400
path="/_mgmt/health",
400-
response_model=Dict,
401+
response_model=(
402+
HealthCheck if self.settings.enable_response_models else None
403+
),
401404
responses={
402405
200: {
403406
"content": {
404407
MimeTypes.json.value: {},
405408
},
409+
"model": HealthCheck,
406410
},
407411
},
408412
response_class=self.response_class,

stac_fastapi/api/stac_fastapi/api/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Api request/response models."""
22

3-
from typing import List, Optional, Type, Union
3+
from typing import List, Literal, Optional, Type, Union
44

55
import attr
66
from fastapi import Path, Query
@@ -135,3 +135,9 @@ class JSONSchemaResponse(JSONResponse):
135135
"""JSON with custom, vendor content-type."""
136136

137137
media_type = "application/schema+json"
138+
139+
140+
class HealthCheck(BaseModel, extra="allow"):
141+
"""health check response model."""
142+
143+
status: Literal["UP", "DOWN"]

stac_fastapi/api/tests/test_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def test_create_get_request_model():
4343
model = request_model(bbox="0,0,0,1,1,1")
4444
assert model.bbox == (0.0, 0.0, 0.0, 1.0, 1.0, 1.0)
4545

46-
with pytest.raises(AssertionError):
46+
with pytest.raises(HTTPException):
47+
request_model(bbox="a,b")
48+
49+
with pytest.raises(HTTPException):
4750
request_model(bbox="0,0,0,1,1")
4851

4952
model = request_model(

stac_fastapi/types/stac_fastapi/types/search.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Dict, List, Optional, Union
66

77
import attr
8-
from fastapi import Query
8+
from fastapi import HTTPException, Query
99
from pydantic import Field, PositiveInt
1010
from pydantic.functional_validators import AfterValidator
1111
from stac_pydantic.api import Search
@@ -34,8 +34,16 @@ def str2list(x: str) -> Optional[List[str]]:
3434
def str2bbox(x: str) -> Optional[BBox]:
3535
"""Convert string to BBox based on , delimiter."""
3636
if x:
37-
t = tuple(float(v) for v in x.split(","))
38-
assert len(t) in [4, 6], f"BBox '{x}' must have 4 or 6 values."
37+
try:
38+
t = tuple(float(v) for v in x.split(","))
39+
except ValueError:
40+
raise HTTPException(status_code=400, detail=f"invalid bbox: {x}")
41+
42+
if len(t) not in (4, 6):
43+
raise HTTPException(
44+
status_code=400, detail=f"BBox '{x}' must have 4 or 6 values."
45+
)
46+
3947
return t
4048

4149
return None

0 commit comments

Comments
 (0)