Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-configurable-request-models
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 authored Jun 28, 2024
2 parents 91d76b7 + 1916d44 commit e577e92
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 15 deletions.
16 changes: 12 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
- `/collections/{collection_id}/items`: **items_get_request_model**, default to `ItemCollectionUri`
- `/collections/{collection_id}/items/{item_id}`: **item_get_request_model**, default to `ItemUri`

### Removed

* Removed the Filter Extension dependency from `AggregationExtensionPostRequest` and `AggregationExtensionGetRequest` [#716](https://github.com/stac-utils/stac-fastapi/pull/716)
* `pagination_extension` attribute in `stac_fastapi.api.app.StacApi`
* remove use of `pagination_extension` in `register_get_item_collection` function (User now need to construct the request model and pass it using `items_get_request_model` attribute)

## [3.0.0a4] - 2024-06-27

### Fixed

* Updated default filter language in filter extension's POST search request model to match the extension's documentation [#711](https://github.com/stac-utils/stac-fastapi/issues/711)

### Removed

* Removed the Filter Extension dependency from `AggregationExtensionPostRequest` and `AggregationExtensionGetRequest` [#716](https://github.com/stac-utils/stac-fastapi/pull/716)
* `pagination_extension` attribute in `stac_fastapi.api.app.StacApi`
* remove use of `pagination_extension` in `register_get_item_collection` function (User now need to construct the request model and pass it using `items_get_request_model` attribute)
* Removed the Filter Extension depenency from `AggregationExtensionPostRequest` and `AggregationExtensionGetRequest` [#716](https://github.com/stac-utils/stac-fastapi/pull/716)
* Removed `add_middleware` method in `StacApi` object and let starlette handle the middleware stack creation [721](https://github.com/stac-utils/stac-fastapi/pull/721)

## [3.0.0a3] - 2024-06-13

Expand Down Expand Up @@ -416,7 +423,8 @@

* First PyPi release!

[Unreleased]: <https://github.com/stac-utils/stac-fastapi/compare/3.0.0a3..main>
[Unreleased]: <https://github.com/stac-utils/stac-fastapi/compare/3.0.0a4..main>
[3.0.0a4]: <https://github.com/stac-utils/stac-fastapi/compare/3.0.0a3..3.0.0a4>
[3.0.0a3]: <https://github.com/stac-utils/stac-fastapi/compare/3.0.0a2..3.0.0a3>
[3.0.0a2]: <https://github.com/stac-utils/stac-fastapi/compare/3.0.0a1..3.0.0a2>
[3.0.0a1]: <https://github.com/stac-utils/stac-fastapi/compare/3.0.0a0..3.0.0a1>
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0a3
3.0.0a4
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ section-order = ["future", "standard-library", "third-party", "first-party", "lo
quote-style = "double"

[tool.bumpversion]
current_version = "3.0.0a3"
current_version = "3.0.0a4"
parse = """(?x)
(?P<major>\\d+)\\.
(?P<minor>\\d+)\\.
Expand Down
10 changes: 4 additions & 6 deletions stac_fastapi/api/stac_fastapi/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,6 @@ def add_route_dependencies(
"""
return add_route_dependencies(self.app.router.routes, scopes, dependencies)

def add_middleware(self, middleware: Middleware):
"""Add a middleware class to the application."""
self.app.user_middleware.insert(0, middleware)
self.app.middleware_stack = self.app.build_middleware_stack()

def __attrs_post_init__(self):
"""Post-init hook.
Expand Down Expand Up @@ -484,8 +479,11 @@ def __attrs_post_init__(self):
self.app.openapi = self.customize_openapi

# add middlewares
if self.middlewares and self.app.middleware_stack is not None:
raise RuntimeError("Cannot add middleware after an application has started")

for middleware in self.middlewares:
self.add_middleware(middleware)
self.app.user_middleware.insert(0, middleware)

# customize route dependencies
for scopes, dependencies in self.route_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/api/stac_fastapi/api/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Library version."""
__version__ = "3.0.0a3"
__version__ = "3.0.0a4"
30 changes: 30 additions & 0 deletions stac_fastapi/api/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from unittest import mock

import pytest
from fastapi import Request
from fastapi.responses import JSONResponse
from starlette.applications import Starlette
from starlette.testclient import TestClient

Expand Down Expand Up @@ -166,3 +168,31 @@ def test_cors_middleware(test_client):
resp = test_client.get("/_mgmt/ping", headers={"Origin": "http://netloc"})
assert resp.status_code == 200
assert resp.headers["access-control-allow-origin"] == "*"


def test_middleware_stack():
stac_api = StacApi(
settings=ApiSettings(), client=mock.create_autospec(BaseCoreClient)
)

def exception_handler(request: Request, exc: Exception) -> JSONResponse:
return JSONResponse(
status_code=400,
content={"customerrordetail": "yoo", "body": "yo"},
)

class CustomException(Exception):
"Custom Exception"

pass

stac_api.app.add_exception_handler(CustomException, exception_handler)

@stac_api.app.get("/error")
def error_endpoint():
raise CustomException("got you!")

with TestClient(stac_api.app) as client:
resp = client.get("/error")
assert resp.status_code == 400
assert resp.json()["customerrordetail"] == "yoo"
2 changes: 1 addition & 1 deletion stac_fastapi/extensions/stac_fastapi/extensions/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Library version."""
__version__ = "3.0.0a3"
__version__ = "3.0.0a4"
2 changes: 1 addition & 1 deletion stac_fastapi/types/stac_fastapi/types/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Library version."""
__version__ = "3.0.0a3"
__version__ = "3.0.0a4"

0 comments on commit e577e92

Please sign in to comment.