Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use same Limit object for collection_items and get_search request model #738

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

### Changed

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

### Added

* Add Free-text Extension ([#655](https://github.com/stac-utils/stac-fastapi/pull/655))
* Add Collection-Search Extension ([#736](https://github.com/stac-utils/stac-fastapi/pull/736))

Expand Down
8 changes: 7 additions & 1 deletion stac_fastapi/api/stac_fastapi/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
APIRequest,
BaseSearchGetRequest,
BaseSearchPostRequest,
Limit,
_bbox_converter,
_datetime_converter,
)
Expand Down Expand Up @@ -113,7 +114,12 @@ class ItemCollectionUri(APIRequest):
"""Get item collection."""

collection_id: Annotated[str, Path(description="Collection ID")] = attr.ib()
limit: Annotated[int, Query()] = attr.ib(default=10)
limit: Annotated[
Optional[Limit],
Query(
description="Limits the number of results that are included in each page of the response (capped to 10_000)." # noqa: E501
),
] = attr.ib(default=10)
bbox: Optional[BBox] = attr.ib(default=None, converter=_bbox_converter)
datetime: Optional[DateTimeType] = attr.ib(
default=None, converter=_datetime_converter
Expand Down
6 changes: 3 additions & 3 deletions stac_fastapi/types/stac_fastapi/types/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ class BaseSearchGetRequest(APIRequest):
default=None, converter=_datetime_converter
)
limit: Annotated[
Optional[int],
Optional[Limit],
Query(
description="Limits the number of results that are included in each page of the response." # noqa: E501
description="Limits the number of results that are included in each page of the response (capped to 10_000)." # noqa: E501
),
] = attr.ib(default=10)

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

limit: Optional[Limit] = Field(
10,
description="Limits the number of results that are included in each page of the response.", # noqa: E501
description="Limits the number of results that are included in each page of the response (capped to 10_000).", # noqa: E501
)
35 changes: 34 additions & 1 deletion stac_fastapi/types/tests/test_limit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from pydantic import ValidationError

from stac_fastapi.types.search import BaseSearchPostRequest
from stac_fastapi.types.search import BaseSearchGetRequest, BaseSearchPostRequest


@pytest.mark.parametrize("value", [0, -1])
Expand All @@ -20,3 +22,34 @@ def test_limit(value):
def test_limit_le(value):
search = BaseSearchPostRequest(limit=value)
assert search.limit == 10_000


def test_limit_get_request():
"""test GET model."""

app = FastAPI()

@app.get("/test")
def route(model=Depends(BaseSearchGetRequest)):
return model

with TestClient(app) as client:
resp = client.get(
"/test",
params={
"limit": 10,
},
)
assert resp.status_code == 200
response_dict = resp.json()
assert response_dict["limit"] == 10

resp = client.get(
"/test",
params={
"limit": 100_000,
},
)
assert resp.status_code == 200
response_dict = resp.json()
assert response_dict["limit"] == 10_000