Skip to content

Commit

Permalink
Merge branch 'main' into feature/move-pagination-models
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 authored Jun 28, 2024
2 parents 812392a + 1916d44 commit 6c5460c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased] - TBD

## [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)
Expand All @@ -10,6 +12,7 @@

* Removed the Filter Extension depenency from `AggregationExtensionPostRequest` and `AggregationExtensionGetRequest` [#716](https://github.com/stac-utils/stac-fastapi/pull/716)
* move `GETPagination`, `POSTPagination`, `GETTokenPagination` and `POSTTokenPagination` to `stac_fastapi.extensions.core.pagination.request` submodule [#717](https://github.com/stac-utils/stac-fastapi/pull/717)
* 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 @@ -407,7 +410,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 @@ -439,11 +439,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 @@ -483,8 +478,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 6c5460c

Please sign in to comment.