diff --git a/CHANGELOG.md b/CHANGELOG.md index 0efad4e5..e4d0aaba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Removed deprecated context extension [#255](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/255) + ## [v3.0.0a0] diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 41d72e7e..3fe7d32e 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -312,22 +312,14 @@ async def item_collection( self.item_serializer.db_to_stac(item, base_url=base_url) for item in items ] - context_obj = None - if self.extension_is_enabled("ContextExtension"): - context_obj = { - "returned": len(items), - "limit": limit, - } - if maybe_count is not None: - context_obj["matched"] = maybe_count - links = await PagingLinks(request=request, next=next_token).get_links() return stac_types.ItemCollection( type="FeatureCollection", features=items, links=links, - context=context_obj, + numReturned=len(items), + numMatched=maybe_count, ) async def get_item( @@ -633,22 +625,14 @@ async def post_search( for feat in items ] - context_obj = None - if self.extension_is_enabled("ContextExtension"): - context_obj = { - "returned": len(items), - "limit": limit, - } - if maybe_count is not None: - context_obj["matched"] = maybe_count - links = await PagingLinks(request=request, next=next_token).get_links() return stac_types.ItemCollection( type="FeatureCollection", features=items, links=links, - context=context_obj, + numReturned=len(items), + numMatched=maybe_count, ) diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py index 49d199d6..c0d4aaea 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py @@ -20,7 +20,6 @@ create_index_templates, ) from stac_fastapi.extensions.core import ( - ContextExtension, FieldsExtension, FilterExtension, SortExtension, @@ -57,7 +56,6 @@ QueryExtension(), SortExtension(), TokenPaginationExtension(), - ContextExtension(), filter_extension, ] diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py index ac697b2b..4cd38c20 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py @@ -14,7 +14,6 @@ from stac_fastapi.core.extensions import QueryExtension from stac_fastapi.core.session import Session from stac_fastapi.extensions.core import ( - ContextExtension, FieldsExtension, FilterExtension, SortExtension, @@ -57,7 +56,6 @@ QueryExtension(), SortExtension(), TokenPaginationExtension(), - ContextExtension(), filter_extension, ] diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index da94338e..8f519a0f 100644 --- a/stac_fastapi/tests/api/test_api.py +++ b/stac_fastapi/tests/api/test_api.py @@ -83,7 +83,7 @@ async def test_app_search_response(app_client, ctx): @pytest.mark.asyncio -async def test_app_context_extension(app_client, txn_client, ctx, load_test_data): +async def test_app_context_results(app_client, txn_client, ctx, load_test_data): test_item = load_test_data("test_item.json") test_item["id"] = "test-item-2" test_item["collection"] = "test-collection-2" @@ -111,9 +111,8 @@ async def test_app_context_extension(app_client, txn_client, ctx, load_test_data resp_json = resp.json() assert len(resp_json["features"]) == 1 - assert "context" in resp_json - assert resp_json["context"]["returned"] == 1 - if matched := resp_json["context"].get("matched"): + assert resp_json["numReturned"] == 1 + if matched := resp_json.get("numMatched"): assert matched == 1 @@ -225,6 +224,7 @@ async def test_app_query_extension_limit_lt0(app_client): ).status_code == 400 +@pytest.mark.skip(reason="removal of context extension") @pytest.mark.asyncio async def test_app_query_extension_limit_gt10000(app_client): resp = await app_client.post("/search", json={"limit": 10001}) diff --git a/stac_fastapi/tests/conftest.py b/stac_fastapi/tests/conftest.py index 80314a45..21380494 100644 --- a/stac_fastapi/tests/conftest.py +++ b/stac_fastapi/tests/conftest.py @@ -38,8 +38,7 @@ create_index_templates, ) -from stac_fastapi.extensions.core import ( # FieldsExtension, - ContextExtension, +from stac_fastapi.extensions.core import ( FieldsExtension, FilterExtension, SortExtension, @@ -193,7 +192,6 @@ async def app(): ), settings=settings, ), - ContextExtension(), SortExtension(), FieldsExtension(), QueryExtension(), @@ -236,7 +234,6 @@ async def app_basic_auth(): ), settings=settings, ), - ContextExtension(), SortExtension(), FieldsExtension(), QueryExtension(), diff --git a/stac_fastapi/tests/resources/test_item.py b/stac_fastapi/tests/resources/test_item.py index 146077bc..ad30c448 100644 --- a/stac_fastapi/tests/resources/test_item.py +++ b/stac_fastapi/tests/resources/test_item.py @@ -215,7 +215,7 @@ async def test_get_item_collection(app_client, ctx, txn_client): assert resp.status_code == 200 item_collection = resp.json() - if matched := item_collection["context"].get("matched"): + if matched := item_collection.get("numMatched"): assert matched == item_count + 1 @@ -283,13 +283,13 @@ async def test_pagination(app_client, load_test_data): ) assert resp.status_code == 200 first_page = resp.json() - assert first_page["context"]["returned"] == 3 + assert first_page["numReturned"] == 3 url_components = urlsplit(first_page["links"][0]["href"]) resp = await app_client.get(f"{url_components.path}?{url_components.query}") assert resp.status_code == 200 second_page = resp.json() - assert second_page["context"]["returned"] == 3 + assert second_page["numReturned"] == 3 @pytest.mark.skip(reason="created and updated fields not be added with stac fastapi 3?") @@ -547,14 +547,14 @@ async def test_item_search_get_query_extension(app_client, ctx): ), } resp = await app_client.get("/search", params=params) - assert resp.json()["context"]["returned"] == 0 + assert resp.json()["numReturned"] == 0 params["query"] = json.dumps( {"proj:epsg": {"eq": test_item["properties"]["proj:epsg"]}} ) resp = await app_client.get("/search", params=params) resp_json = resp.json() - assert resp_json["context"]["returned"] == 1 + assert resp_json["numReturned"] == 1 assert ( resp_json["features"][0]["properties"]["proj:epsg"] == test_item["properties"]["proj:epsg"]