Skip to content

Commit f11e27e

Browse files
fix search self link mediatype (stac-utils#217)
1 parent 4a34c90 commit f11e27e

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
## [5.0.1] - 2025-03-27
6+
7+
### Fixed
8+
9+
- fix media type for `self` links in `/search` responses
10+
511
## [5.0.0] - 2025-03-10
612

713
### Changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.0
1+
5.0.1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ignore = [
2929

3030

3131
[tool.bumpversion]
32-
current_version = "5.0.0"
32+
current_version = "5.0.1"
3333
parse = """(?x)
3434
(?P<major>\\d+)\\.
3535
(?P<minor>\\d+)\\.

stac_fastapi/pgstac/core.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
ItemCollectionLinks,
2929
ItemLinks,
3030
PagingLinks,
31+
SearchLinks,
3132
)
3233
from stac_fastapi.pgstac.types.search import PgstacSearch
3334
from stac_fastapi.pgstac.utils import filter_fields
@@ -466,6 +467,11 @@ async def post_search(
466467
if fields.include or fields.exclude:
467468
return JSONResponse(item_collection) # type: ignore
468469

470+
links = await SearchLinks(request=request).get_links(
471+
extra_links=item_collection["links"]
472+
)
473+
item_collection["links"] = links
474+
469475
return ItemCollection(**item_collection)
470476

471477
async def get_search(
@@ -522,6 +528,11 @@ async def get_search(
522528

523529
item_collection = await self._search_base(search_request, request=request)
524530

531+
links = await SearchLinks(request=request).get_links(
532+
extra_links=item_collection["links"]
533+
)
534+
item_collection["links"] = links
535+
525536
# If we have the `fields` extension enabled
526537
# we need to avoid Pydantic validation because the
527538
# Items might not be a valid STAC Item objects

stac_fastapi/pgstac/models/links.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,19 @@ def link_items(self) -> Dict:
266266
}
267267

268268

269+
@attr.s
270+
class SearchLinks(BaseLinks):
271+
"""Create inferred links specific to collections."""
272+
273+
def link_self(self) -> Dict:
274+
"""Return the self link."""
275+
return {
276+
"rel": Relations.self.value,
277+
"type": MimeTypes.geojson.value,
278+
"href": self.resolve("search"),
279+
}
280+
281+
269282
@attr.s
270283
class ItemCollectionLinks(CollectionLinksBase):
271284
"""Create inferred links specific to collections."""

stac_fastapi/pgstac/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""library version."""
22

3-
__version__ = "5.0.0"
3+
__version__ = "5.0.1"

tests/resources/test_item.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,3 +1662,22 @@ async def test_get_filter_extension(app_client, load_test_data, load_test_collec
16621662
fc = resp.json()
16631663
assert len(fc["features"]) == 1
16641664
assert fc["features"][0]["id"] == search_id
1665+
1666+
1667+
async def test_get_search_link_media(app_client):
1668+
"""Test Search request returned links"""
1669+
# GET
1670+
resp = await app_client.get("/search")
1671+
assert resp.status_code == 200
1672+
links = resp.json()["links"]
1673+
assert len(links) == 2
1674+
get_self_link = next((link for link in links if link["rel"] == "self"), None)
1675+
assert get_self_link["type"] == "application/geo+json"
1676+
1677+
# POST
1678+
resp = await app_client.post("/search", json={})
1679+
assert resp.status_code == 200
1680+
links = resp.json()["links"]
1681+
assert len(links) == 2
1682+
get_self_link = next((link for link in links if link["rel"] == "self"), None)
1683+
assert get_self_link["type"] == "application/geo+json"

0 commit comments

Comments
 (0)