|
1 | 1 | """Fastapi app creation.""" |
2 | 2 |
|
3 | 3 |
|
| 4 | +import inspect |
4 | 5 | from typing import Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union |
5 | 6 |
|
6 | 7 | import attr |
7 | 8 | from brotli_asgi import BrotliMiddleware |
8 | 9 | from fastapi import APIRouter, FastAPI |
9 | 10 | from fastapi.params import Depends |
10 | 11 | from stac_pydantic import api |
11 | | -from stac_pydantic.api.collections import Collections |
12 | 12 | from stac_pydantic.shared import MimeTypes |
13 | 13 | from stac_pydantic.version import STAC_VERSION |
14 | 14 | from starlette.middleware import Middleware |
|
32 | 32 | add_direct_response, |
33 | 33 | add_route_dependencies, |
34 | 34 | create_async_endpoint, |
| 35 | + sync_to_async, |
35 | 36 | ) |
36 | 37 | from stac_fastapi.types.config import ApiSettings, Settings |
37 | 38 | from stac_fastapi.types.core import AsyncBaseCoreClient, BaseCoreClient |
@@ -277,14 +278,14 @@ def register_get_collections(self) -> None: |
277 | 278 | name="Get Collections", |
278 | 279 | path="/collections", |
279 | 280 | response_model=( |
280 | | - Collections if self.settings.enable_response_models else None |
| 281 | + api.Collections if self.settings.enable_response_models else None |
281 | 282 | ), |
282 | 283 | responses={ |
283 | 284 | 200: { |
284 | 285 | "content": { |
285 | 286 | MimeTypes.json.value: {}, |
286 | 287 | }, |
287 | | - "model": Collections, |
| 288 | + "model": api.Collections, |
288 | 289 | }, |
289 | 290 | }, |
290 | 291 | response_class=self.response_class, |
@@ -411,7 +412,9 @@ async def ping(): |
411 | 412 | }, |
412 | 413 | response_class=self.response_class, |
413 | 414 | methods=["GET"], |
414 | | - endpoint=self.health_check, |
| 415 | + endpoint=self.health_check |
| 416 | + if inspect.iscoroutinefunction(self.health_check) |
| 417 | + else sync_to_async(self.health_check), |
415 | 418 | ) |
416 | 419 | self.app.include_router(mgmt_router, tags=["Liveliness/Readiness"]) |
417 | 420 |
|
|
0 commit comments