Skip to content

Commit 900a5dd

Browse files
committed
enable direct response, 5.2.0, deprecation warnings
1 parent 5f91e50 commit 900a5dd

File tree

8 files changed

+39
-19
lines changed

8 files changed

+39
-19
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Changed
11+
- Migrated Elasticsearch index template creation from legacy `put_template` to composable `put_index_template` API in `database_logic.py`. This resolves deprecation warnings and ensures compatibility with Elasticsearch 7.x and 8.x.
12+
- Updated all Pydantic models to use `ConfigDict` instead of class-based `Config` for Pydantic v2 compatibility. This resolves deprecation warnings and prepares for Pydantic v3.
13+
- Migrated all Pydantic `@root_validator` validators to `@model_validator` for Pydantic v2 compatibility.
14+
1015
### Added
16+
- Added `enable_direct_response` option to API settings for more flexible response handling.
1117

1218
### Changed
19+
- Updated test suite to use `httpx.ASGITransport(app=...)` for FastAPI app testing (removes deprecation warning).
20+
- Updated stac-fastapi parent libraries to 5.2.0.
1321

1422
### Fixed
1523

stac_fastapi/core/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"attrs>=23.2.0",
1111
"pydantic>=2.4.1,<3.0.0",
1212
"stac_pydantic~=3.1.0",
13-
"stac-fastapi.api==5.1.1",
14-
"stac-fastapi.extensions==5.1.1",
15-
"stac-fastapi.types==5.1.1",
13+
"stac-fastapi.api==5.2.0",
14+
"stac-fastapi.extensions==5.2.0",
15+
"stac-fastapi.types==5.2.0",
1616
"orjson~=3.9.0",
1717
"overrides~=7.4.0",
1818
"geojson-pydantic~=1.0.0",

stac_fastapi/core/stac_fastapi/core/extensions/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from types import DynamicClassAttribute
1111
from typing import Any, Callable, Dict, Optional
1212

13-
from pydantic import BaseModel, root_validator
13+
from pydantic import BaseModel, model_validator
1414
from stac_pydantic.utils import AutoValueEnum
1515

1616
from stac_fastapi.extensions.core.query import QueryExtension as QueryExtensionBase
@@ -63,7 +63,7 @@ class QueryExtensionPostRequest(BaseModel):
6363

6464
query: Optional[Dict[str, Dict[Operator, Any]]] = None
6565

66-
@root_validator(pre=True)
66+
@model_validator(mode="before")
6767
def validate_query_fields(cls, values: Dict) -> Dict:
6868
"""Validate query fields."""
6969
...

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
api = StacApi(
8888
title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-elasticsearch"),
8989
description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-elasticsearch"),
90-
api_version=os.getenv("STAC_FASTAPI_VERSION", "2.1"),
90+
api_version=os.getenv("STAC_FASTAPI_VERSION", "5.2.0"),
9191
settings=settings,
9292
extensions=extensions,
9393
client=CoreClient(
@@ -96,6 +96,8 @@
9696
search_get_request_model=create_get_request_model(search_extensions),
9797
search_post_request_model=post_request_model,
9898
route_dependencies=get_route_dependencies(),
99+
enable_response_models=False,
100+
enable_direct_response=True,
99101
)
100102
app = api.app
101103
app.root_path = os.getenv("STAC_FASTAPI_ROOT_PATH", "")

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ async def create_index_templates() -> None:
5050
5151
"""
5252
client = AsyncElasticsearchSettings().create_client
53-
await client.indices.put_template(
53+
await client.indices.put_index_template(
5454
name=f"template_{COLLECTIONS_INDEX}",
5555
body={
5656
"index_patterns": [f"{COLLECTIONS_INDEX}*"],
57-
"mappings": ES_COLLECTIONS_MAPPINGS,
57+
"template": {"mappings": ES_COLLECTIONS_MAPPINGS},
5858
},
5959
)
60-
await client.indices.put_template(
60+
await client.indices.put_index_template(
6161
name=f"template_{ITEMS_INDEX_PREFIX}",
6262
body={
6363
"index_patterns": [f"{ITEMS_INDEX_PREFIX}*"],
64-
"settings": ES_ITEMS_SETTINGS,
65-
"mappings": ES_ITEMS_MAPPINGS,
64+
"template": {"settings": ES_ITEMS_SETTINGS, "mappings": ES_ITEMS_MAPPINGS},
6665
},
6766
)
6867
await client.close()

stac_fastapi/opensearch/stac_fastapi/opensearch/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
api = StacApi(
8888
title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-opensearch"),
8989
description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-opensearch"),
90-
api_version=os.getenv("STAC_FASTAPI_VERSION", "2.1"),
90+
api_version=os.getenv("STAC_FASTAPI_VERSION", "5.2.0"),
9191
settings=settings,
9292
extensions=extensions,
9393
client=CoreClient(
@@ -96,10 +96,13 @@
9696
search_get_request_model=create_get_request_model(search_extensions),
9797
search_post_request_model=post_request_model,
9898
route_dependencies=get_route_dependencies(),
99+
enable_response_models=False,
100+
enable_direct_response=True,
99101
)
100102
app = api.app
101103
app.root_path = os.getenv("STAC_FASTAPI_ROOT_PATH", "")
102104

105+
103106
# Add rate limit
104107
setup_rate_limit(app, rate_limit=os.getenv("STAC_FASTAPI_RATE_LIMIT"))
105108

stac_fastapi/tests/api/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
ROUTES = {
99
"GET /_mgmt/ping",
10+
"GET /_mgmt/health",
1011
"GET /docs/oauth2-redirect",
1112
"HEAD /docs/oauth2-redirect",
1213
"GET /",

stac_fastapi/tests/conftest.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import pytest
99
import pytest_asyncio
1010
from fastapi import Depends, HTTPException, security, status
11-
from httpx import AsyncClient
11+
from httpx import ASGITransport, AsyncClient
12+
from pydantic import ConfigDict
1213
from stac_pydantic import api
1314

1415
from stac_fastapi.api.app import StacApi
@@ -85,8 +86,7 @@ def __init__(
8586

8687

8788
class TestSettings(AsyncSettings):
88-
class Config:
89-
env_file = ".env.test"
89+
model_config = ConfigDict(env_file=".env.test")
9090

9191

9292
settings = TestSettings()
@@ -243,7 +243,9 @@ async def app_client(app):
243243
await create_index_templates()
244244
await create_collection_index()
245245

246-
async with AsyncClient(app=app, base_url="http://test-server") as c:
246+
async with AsyncClient(
247+
transport=ASGITransport(app=app), base_url="http://test-server"
248+
) as c:
247249
yield c
248250

249251

@@ -302,7 +304,9 @@ async def app_client_rate_limit(app_rate_limit):
302304
await create_index_templates()
303305
await create_collection_index()
304306

305-
async with AsyncClient(app=app_rate_limit, base_url="http://test-server") as c:
307+
async with AsyncClient(
308+
transport=ASGITransport(app=app_rate_limit), base_url="http://test-server"
309+
) as c:
306310
yield c
307311

308312

@@ -392,7 +396,9 @@ async def app_client_basic_auth(app_basic_auth):
392396
await create_index_templates()
393397
await create_collection_index()
394398

395-
async with AsyncClient(app=app_basic_auth, base_url="http://test-server") as c:
399+
async with AsyncClient(
400+
transport=ASGITransport(app=app_basic_auth), base_url="http://test-server"
401+
) as c:
396402
yield c
397403

398404

@@ -469,6 +475,7 @@ async def route_dependencies_client(route_dependencies_app):
469475
await create_collection_index()
470476

471477
async with AsyncClient(
472-
app=route_dependencies_app, base_url="http://test-server"
478+
transport=ASGITransport(app=route_dependencies_app),
479+
base_url="http://test-server",
473480
) as c:
474481
yield c

0 commit comments

Comments
 (0)