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

removed fields which are added by extensions from the base Search mod… #100

Merged
merged 5 commits into from
May 2, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Unreleased

2.0.2 (2021-11-22)
------------------
- Remove fields added by STAC API search extensions (#100, @rsmith013 & @moradology)
- Add ExtendedSearch class with fields from STAC API search extensions (#100, @rsmith013 & @moradology)
- Allow for non-ellipsis open temporal windows (#103, @moradology)
- Add the canonical and service-doc relation types (#104, @moradology)

Expand Down
17 changes: 13 additions & 4 deletions stac_pydantic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

class Search(BaseModel):
"""
The base class for STAC API searches.

https://github.com/radiantearth/stac-api-spec/blob/master/api-spec.md#filter-parameters-and-fields
"""

collections: List[str]
collections: Optional[List[str]]
ids: Optional[List[str]]
bbox: Optional[BBox]
intersects: Optional[
Expand All @@ -41,9 +43,6 @@ class Search(BaseModel):
]
datetime: Optional[str]
limit: int = 10
field: Optional[FieldsExtension] = Field(None, alias="fields")
query: Optional[Dict[str, Dict[Operator, Any]]]
sortby: Optional[List[SortExtension]]

@property
def start_date(self) -> Optional[datetime]:
Expand Down Expand Up @@ -144,3 +143,13 @@ def spatial_filter(self) -> Optional[_GeometryBase]:
if self.intersects:
return self.intersects
return


class ExtendedSearch(Search):
"""
STAC API search with extensions enabled.
"""

field: Optional[FieldsExtension] = Field(None, alias="fields")
query: Optional[Dict[str, Dict[Operator, Any]]]
sortby: Optional[List[SortExtension]]
1 change: 0 additions & 1 deletion stac_pydantic/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Item(Feature):
properties: ItemProperties
assets: Dict[str, Asset]
links: Links
bbox: Optional[BBox]
stac_extensions: Optional[List[AnyUrl]]
collection: Optional[str]

Expand Down
8 changes: 4 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from stac_pydantic.api import Collections
from stac_pydantic.api.conformance import ConformanceClasses
from stac_pydantic.api.landing import LandingPage
from stac_pydantic.api.search import Search
from stac_pydantic.api.search import ExtendedSearch, Search
from stac_pydantic.extensions import validate_extensions
from stac_pydantic.links import Link, Links, PaginationLink
from stac_pydantic.shared import DATETIME_RFC339
Expand Down Expand Up @@ -410,14 +410,14 @@ def test_api_query_extension():
def test_api_query_extension_invalid():
# Invalid operator
with pytest.raises(ValidationError):
Search(
ExtendedSearch(
collections=["collection1", "collection2"],
query={"field": {"greater_than": 100}},
)


def test_api_sort_extension():
Search(
ExtendedSearch(
collections=["collection1", "collection2"],
sortby=[
{"field": "field1", "direction": "asc"},
Expand All @@ -429,7 +429,7 @@ def test_api_sort_extension():
def test_api_sort_extension_invalid():
# Invalid sort direction
with pytest.raises(ValidationError):
Search(
ExtendedSearch(
collections=["collection1", "collection2"],
sortby=[{"field": "field1", "direction": "ascending"}],
)
Expand Down