Skip to content

Commit

Permalink
add deprecation warning for the ContextExtension (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Apr 11, 2024
1 parent 96de0e2 commit f7d2eb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add benchmark in CI ([#650](https://github.com/stac-utils/stac-fastapi/pull/650))
* Add `/queryables` link to the landing page ([#587](https://github.com/stac-utils/stac-fastapi/pull/587))
- `id`, `title`, `description` and `api_version` fields can be customized via env variables
* Add `DeprecationWarning` for the `ContextExtension`

### Changed

Expand Down
5 changes: 5 additions & 0 deletions docs/src/tips-and-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ If needed, you can edit the `allow_origins` parameter to only allow CORS request

## Enable the Context extension

!!! Warning

The `ContextExtension` is deprecated and will be removed in 3.0. See https://github.com/radiantearth/stac-api-spec/issues/396

The Context STAC extension provides information on the number of items matched and returned from a STAC search.
This is required by various other STAC-related tools, such as the pystac command-line client.
To enable the extension, edit your backend's `app.py` and add the following import:
Expand All @@ -30,6 +34,7 @@ To enable the extension, edit your backend's `app.py` and add the following impo
from stac_fastapi.extensions.core.context import ContextExtension
```


and then edit the `api = StacApi(...` call to add `ContextExtension()` to the list given as the `extensions` parameter.

## Set API title, description and version
Expand Down
10 changes: 10 additions & 0 deletions stac_fastapi/extensions/stac_fastapi/extensions/core/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Context extension."""

import warnings
from typing import List, Optional

import attr
Expand All @@ -24,6 +26,14 @@ class ContextExtension(ApiExtension):
default="https://raw.githubusercontent.com/stac-api-extensions/context/v1.0.0-rc.2/json-schema/schema.json"
)

def __attrs_post_init__(self):
"""init."""
warnings.warm(
"The ContextExtension is deprecated and will be removed in 3.0.",
DeprecationWarning,
stacklevel=1,
)

def register(self, app: FastAPI) -> None:
"""Register the extension with a FastAPI application.
Expand Down

0 comments on commit f7d2eb3

Please sign in to comment.