|
1 | 1 | """openapi.""" |
2 | 2 |
|
3 | | -import warnings |
4 | | - |
5 | 3 | from fastapi import FastAPI |
6 | | -from fastapi.openapi.utils import get_openapi |
7 | 4 | from starlette.requests import Request |
8 | 5 | from starlette.responses import JSONResponse, Response |
9 | 6 | from starlette.routing import Route, request_response |
10 | 7 |
|
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 | 8 |
|
29 | 9 | def update_openapi(app: FastAPI) -> FastAPI: |
30 | 10 | """Update OpenAPI response content-type. |
@@ -55,33 +35,3 @@ async def patched_openapi_endpoint(req: Request) -> Response: |
55 | 35 |
|
56 | 36 | # return the patched app |
57 | 37 | 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 |
0 commit comments