stac-fastapi.api 3.0.0b3__tar.gz → 3.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/PKG-INFO +2 -2
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/setup.py +1 -1
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/config.py +0 -1
- stac_fastapi_api-3.0.1/stac_fastapi/api/openapi.py +37 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/routes.py +0 -8
- stac_fastapi_api-3.0.1/stac_fastapi/api/version.py +3 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/PKG-INFO +2 -2
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/requires.txt +1 -1
- stac_fastapi_api-3.0.0b3/stac_fastapi/api/openapi.py +0 -87
- stac_fastapi_api-3.0.0b3/stac_fastapi/api/version.py +0 -2
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/README.md +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/setup.cfg +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/__init__.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/app.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/errors.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/middleware.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi/api/models.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/SOURCES.txt +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/dependency_links.txt +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/not-zip-safe +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/top_level.txt +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/tests/test_api.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/tests/test_app.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/tests/test_app_prefix.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/tests/test_middleware.py +0 -0
- {stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/tests/test_models.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stac-fastapi.api
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: An implementation of STAC API based on the FastAPI framework.
|
|
5
5
|
Home-page: https://github.com/stac-utils/stac-fastapi
|
|
6
6
|
Author: Arturo Engineering
|
|
@@ -19,7 +19,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
19
19
|
Requires-Python: >=3.8
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
Requires-Dist: brotli_asgi
|
|
22
|
-
Requires-Dist: stac-fastapi.types
|
|
22
|
+
Requires-Dist: stac-fastapi.types~=3.0
|
|
23
23
|
Provides-Extra: dev
|
|
24
24
|
Requires-Dist: httpx; extra == "dev"
|
|
25
25
|
Requires-Dist: pytest; extra == "dev"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""openapi."""
|
|
2
|
+
|
|
3
|
+
from fastapi import FastAPI
|
|
4
|
+
from starlette.requests import Request
|
|
5
|
+
from starlette.responses import JSONResponse, Response
|
|
6
|
+
from starlette.routing import Route, request_response
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def update_openapi(app: FastAPI) -> FastAPI:
|
|
10
|
+
"""Update OpenAPI response content-type.
|
|
11
|
+
|
|
12
|
+
This function modifies the openapi route to comply with the STAC API spec's required
|
|
13
|
+
content-type response header.
|
|
14
|
+
"""
|
|
15
|
+
# Find the route for the openapi_url in the app
|
|
16
|
+
openapi_route: Route = next(
|
|
17
|
+
route for route in app.router.routes if route.path == app.openapi_url
|
|
18
|
+
)
|
|
19
|
+
# Store the old endpoint function so we can call it from the patched function
|
|
20
|
+
old_endpoint = openapi_route.endpoint
|
|
21
|
+
|
|
22
|
+
# Create a patched endpoint function that modifies the content type of the response
|
|
23
|
+
async def patched_openapi_endpoint(req: Request) -> Response:
|
|
24
|
+
# Get the response from the old endpoint function
|
|
25
|
+
response: JSONResponse = await old_endpoint(req)
|
|
26
|
+
# Update the content type header in place
|
|
27
|
+
response.headers["content-type"] = "application/vnd.oai.openapi+json;version=3.0"
|
|
28
|
+
# Return the updated response
|
|
29
|
+
return response
|
|
30
|
+
|
|
31
|
+
# When a Route is accessed the `handle` function calls `self.app`. Which is
|
|
32
|
+
# the endpoint function wrapped with `request_response`. So we need to wrap
|
|
33
|
+
# our patched function and replace the existing app with it.
|
|
34
|
+
openapi_route.app = request_response(patched_openapi_endpoint)
|
|
35
|
+
|
|
36
|
+
# return the patched app
|
|
37
|
+
return app
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import copy
|
|
4
4
|
import functools
|
|
5
5
|
import inspect
|
|
6
|
-
import warnings
|
|
7
6
|
from typing import Any, Callable, Dict, List, Optional, Type, TypedDict, Union
|
|
8
7
|
|
|
9
8
|
from fastapi import Depends, params
|
|
@@ -38,19 +37,12 @@ def sync_to_async(func):
|
|
|
38
37
|
def create_async_endpoint(
|
|
39
38
|
func: Callable,
|
|
40
39
|
request_model: Union[Type[APIRequest], Type[BaseModel], Dict],
|
|
41
|
-
response_class: Optional[Type[Response]] = None,
|
|
42
40
|
):
|
|
43
41
|
"""Wrap a function in a coroutine which may be used to create a FastAPI endpoint.
|
|
44
42
|
|
|
45
43
|
Synchronous functions are executed asynchronously using a background thread.
|
|
46
44
|
"""
|
|
47
45
|
|
|
48
|
-
if response_class:
|
|
49
|
-
warnings.warn(
|
|
50
|
-
"`response_class` option is deprecated, please set the Response class directly in the endpoint.", # noqa: E501
|
|
51
|
-
DeprecationWarning,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
46
|
if not inspect.iscoroutinefunction(func):
|
|
55
47
|
func = sync_to_async(func)
|
|
56
48
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stac-fastapi.api
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: An implementation of STAC API based on the FastAPI framework.
|
|
5
5
|
Home-page: https://github.com/stac-utils/stac-fastapi
|
|
6
6
|
Author: Arturo Engineering
|
|
@@ -19,7 +19,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
19
19
|
Requires-Python: >=3.8
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
Requires-Dist: brotli_asgi
|
|
22
|
-
Requires-Dist: stac-fastapi.types
|
|
22
|
+
Requires-Dist: stac-fastapi.types~=3.0
|
|
23
23
|
Provides-Extra: dev
|
|
24
24
|
Requires-Dist: httpx; extra == "dev"
|
|
25
25
|
Requires-Dist: pytest; extra == "dev"
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"""openapi."""
|
|
2
|
-
|
|
3
|
-
import warnings
|
|
4
|
-
|
|
5
|
-
from fastapi import FastAPI
|
|
6
|
-
from fastapi.openapi.utils import get_openapi
|
|
7
|
-
from starlette.requests import Request
|
|
8
|
-
from starlette.responses import JSONResponse, Response
|
|
9
|
-
from starlette.routing import Route, request_response
|
|
10
|
-
|
|
11
|
-
from stac_fastapi.api.config import ApiExtensions
|
|
12
|
-
from stac_fastapi.types.config import ApiSettings
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class VndOaiResponse(JSONResponse):
|
|
16
|
-
"""JSON with custom, vendor content-type."""
|
|
17
|
-
|
|
18
|
-
media_type = "application/vnd.oai.openapi+json;version=3.0"
|
|
19
|
-
|
|
20
|
-
def __init__(self, *args, **kwargs):
|
|
21
|
-
"""Init function with deprecation warning."""
|
|
22
|
-
warnings.warn(
|
|
23
|
-
"VndOaiResponse is deprecated and will be removed in v3.0",
|
|
24
|
-
DeprecationWarning,
|
|
25
|
-
)
|
|
26
|
-
super().__init__(*args, **kwargs)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def update_openapi(app: FastAPI) -> FastAPI:
|
|
30
|
-
"""Update OpenAPI response content-type.
|
|
31
|
-
|
|
32
|
-
This function modifies the openapi route to comply with the STAC API spec's required
|
|
33
|
-
content-type response header.
|
|
34
|
-
"""
|
|
35
|
-
# Find the route for the openapi_url in the app
|
|
36
|
-
openapi_route: Route = next(
|
|
37
|
-
route for route in app.router.routes if route.path == app.openapi_url
|
|
38
|
-
)
|
|
39
|
-
# Store the old endpoint function so we can call it from the patched function
|
|
40
|
-
old_endpoint = openapi_route.endpoint
|
|
41
|
-
|
|
42
|
-
# Create a patched endpoint function that modifies the content type of the response
|
|
43
|
-
async def patched_openapi_endpoint(req: Request) -> Response:
|
|
44
|
-
# Get the response from the old endpoint function
|
|
45
|
-
response: JSONResponse = await old_endpoint(req)
|
|
46
|
-
# Update the content type header in place
|
|
47
|
-
response.headers["content-type"] = "application/vnd.oai.openapi+json;version=3.0"
|
|
48
|
-
# Return the updated response
|
|
49
|
-
return response
|
|
50
|
-
|
|
51
|
-
# When a Route is accessed the `handle` function calls `self.app`. Which is
|
|
52
|
-
# the endpoint function wrapped with `request_response`. So we need to wrap
|
|
53
|
-
# our patched function and replace the existing app with it.
|
|
54
|
-
openapi_route.app = request_response(patched_openapi_endpoint)
|
|
55
|
-
|
|
56
|
-
# return the patched app
|
|
57
|
-
return app
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def config_openapi(app: FastAPI, settings: ApiSettings):
|
|
61
|
-
"""Config openapi."""
|
|
62
|
-
warnings.warn(
|
|
63
|
-
"config_openapi is deprecated and will be removed in v3.0",
|
|
64
|
-
DeprecationWarning,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
def custom_openapi():
|
|
68
|
-
"""Config openapi."""
|
|
69
|
-
if app.openapi_schema:
|
|
70
|
-
return app.openapi_schema
|
|
71
|
-
|
|
72
|
-
openapi_schema = get_openapi(
|
|
73
|
-
title="Arturo STAC API", version="0.1", routes=app.routes
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
if settings.api_extension_is_enabled(ApiExtensions.fields):
|
|
77
|
-
openapi_schema["paths"]["/search"]["get"]["responses"]["200"]["content"][
|
|
78
|
-
"application/json"
|
|
79
|
-
]["schema"] = {"$ref": "#/components/schemas/ItemCollection"}
|
|
80
|
-
openapi_schema["paths"]["/search"]["post"]["responses"]["200"]["content"][
|
|
81
|
-
"application/json"
|
|
82
|
-
]["schema"] = {"$ref": "#/components/schemas/ItemCollection"}
|
|
83
|
-
|
|
84
|
-
app.openapi_schema = openapi_schema
|
|
85
|
-
return app.openapi_schema
|
|
86
|
-
|
|
87
|
-
app.openapi = custom_openapi
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stac_fastapi_api-3.0.0b3 → stac_fastapi_api-3.0.1}/stac_fastapi.api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|