Skip to content

Commit 69dcee0

Browse files
use same Limit object for collection_items and get_search request model (#738)
* use same Limit object for collection_items and get_search request model * add tests
1 parent 4df4947 commit 69dcee0

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
### Changed
66

7-
* add more openapi metadata in input models [#734](https://github.com/stac-utils/stac-fastapi/pull/734)
7+
* Add more openapi metadata in input models [#734](https://github.com/stac-utils/stac-fastapi/pull/734)
8+
* Use same `Limit` (capped to `10_000`) for `/items` and `GET - /search` input models ([#737](https://github.com/stac-utils/stac-fastapi/pull/737))
89

910
### Added
11+
1012
* Add Free-text Extension ([#655](https://github.com/stac-utils/stac-fastapi/pull/655))
1113
* Add Collection-Search Extension ([#736](https://github.com/stac-utils/stac-fastapi/pull/736))
1214

stac_fastapi/api/stac_fastapi/api/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
APIRequest,
1515
BaseSearchGetRequest,
1616
BaseSearchPostRequest,
17+
Limit,
1718
_bbox_converter,
1819
_datetime_converter,
1920
)
@@ -113,7 +114,12 @@ class ItemCollectionUri(APIRequest):
113114
"""Get item collection."""
114115

115116
collection_id: Annotated[str, Path(description="Collection ID")] = attr.ib()
116-
limit: Annotated[int, Query()] = attr.ib(default=10)
117+
limit: Annotated[
118+
Optional[Limit],
119+
Query(
120+
description="Limits the number of results that are included in each page of the response (capped to 10_000)." # noqa: E501
121+
),
122+
] = attr.ib(default=10)
117123
bbox: Optional[BBox] = attr.ib(default=None, converter=_bbox_converter)
118124
datetime: Optional[DateTimeType] = attr.ib(
119125
default=None, converter=_datetime_converter

stac_fastapi/types/stac_fastapi/types/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ class BaseSearchGetRequest(APIRequest):
174174
default=None, converter=_datetime_converter
175175
)
176176
limit: Annotated[
177-
Optional[int],
177+
Optional[Limit],
178178
Query(
179-
description="Limits the number of results that are included in each page of the response." # noqa: E501
179+
description="Limits the number of results that are included in each page of the response (capped to 10_000)." # noqa: E501
180180
),
181181
] = attr.ib(default=10)
182182

@@ -186,5 +186,5 @@ class BaseSearchPostRequest(Search):
186186

187187
limit: Optional[Limit] = Field(
188188
10,
189-
description="Limits the number of results that are included in each page of the response.", # noqa: E501
189+
description="Limits the number of results that are included in each page of the response (capped to 10_000).", # noqa: E501
190190
)

stac_fastapi/types/tests/test_limit.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pytest
2+
from fastapi import Depends, FastAPI
3+
from fastapi.testclient import TestClient
24
from pydantic import ValidationError
35

4-
from stac_fastapi.types.search import BaseSearchPostRequest
6+
from stac_fastapi.types.search import BaseSearchGetRequest, BaseSearchPostRequest
57

68

79
@pytest.mark.parametrize("value", [0, -1])
@@ -20,3 +22,34 @@ def test_limit(value):
2022
def test_limit_le(value):
2123
search = BaseSearchPostRequest(limit=value)
2224
assert search.limit == 10_000
25+
26+
27+
def test_limit_get_request():
28+
"""test GET model."""
29+
30+
app = FastAPI()
31+
32+
@app.get("/test")
33+
def route(model=Depends(BaseSearchGetRequest)):
34+
return model
35+
36+
with TestClient(app) as client:
37+
resp = client.get(
38+
"/test",
39+
params={
40+
"limit": 10,
41+
},
42+
)
43+
assert resp.status_code == 200
44+
response_dict = resp.json()
45+
assert response_dict["limit"] == 10
46+
47+
resp = client.get(
48+
"/test",
49+
params={
50+
"limit": 100_000,
51+
},
52+
)
53+
assert resp.status_code == 200
54+
response_dict = resp.json()
55+
assert response_dict["limit"] == 10_000

0 commit comments

Comments
 (0)