1
1
"""Fastapi app creation."""
2
2
3
3
4
- from typing import Any , Dict , List , Optional , Tuple , Type , Union
4
+ from typing import Dict , List , Optional , Tuple , Type , Union
5
5
6
6
import attr
7
7
from brotli_asgi import BrotliMiddleware
8
8
from fastapi import APIRouter , FastAPI
9
- from fastapi .openapi .utils import get_openapi
10
9
from fastapi .params import Depends
11
10
from stac_pydantic import api
12
11
from stac_pydantic .api .collections import Collections
@@ -71,19 +70,6 @@ class StacApi:
71
70
exceptions : Dict [Type [Exception ], int ] = attr .ib (
72
71
default = attr .Factory (lambda : DEFAULT_STATUS_CODES )
73
72
)
74
- app : FastAPI = attr .ib (
75
- default = attr .Factory (
76
- lambda self : FastAPI (
77
- openapi_url = self .settings .openapi_url ,
78
- docs_url = self .settings .docs_url ,
79
- redoc_url = None ,
80
- root_path = self .settings .root_path ,
81
- ),
82
- takes_self = True ,
83
- ),
84
- converter = update_openapi ,
85
- )
86
- router : APIRouter = attr .ib (default = attr .Factory (APIRouter ))
87
73
title : str = attr .ib (
88
74
default = attr .Factory (
89
75
lambda self : self .settings .stac_fastapi_title , takes_self = True
@@ -100,6 +86,22 @@ class StacApi:
100
86
lambda self : self .settings .stac_fastapi_description , takes_self = True
101
87
)
102
88
)
89
+ app : FastAPI = attr .ib (
90
+ default = attr .Factory (
91
+ lambda self : FastAPI (
92
+ openapi_url = self .settings .openapi_url ,
93
+ docs_url = self .settings .docs_url ,
94
+ redoc_url = None ,
95
+ root_path = self .settings .root_path ,
96
+ title = self .title ,
97
+ version = self .api_version ,
98
+ description = self .description ,
99
+ ),
100
+ takes_self = True ,
101
+ ),
102
+ converter = update_openapi ,
103
+ )
104
+ router : APIRouter = attr .ib (default = attr .Factory (APIRouter ))
103
105
search_get_request_model : Type [BaseSearchGetRequest ] = attr .ib (
104
106
default = BaseSearchGetRequest
105
107
)
@@ -388,22 +390,6 @@ def register_core(self):
388
390
self .register_get_collection ()
389
391
self .register_get_item_collection ()
390
392
391
- def customize_openapi (self ) -> Optional [Dict [str , Any ]]:
392
- """Customize openapi schema."""
393
- if self .app .openapi_schema :
394
- return self .app .openapi_schema
395
-
396
- openapi_schema = get_openapi (
397
- title = self .title ,
398
- version = self .api_version ,
399
- description = self .description ,
400
- routes = self .app .routes ,
401
- servers = self .app .servers ,
402
- )
403
-
404
- self .app .openapi_schema = openapi_schema
405
- return self .app .openapi_schema
406
-
407
393
def add_health_check (self ):
408
394
"""Add a health check."""
409
395
mgmt_router = APIRouter (prefix = self .app .state .router_prefix )
@@ -467,9 +453,6 @@ def __attrs_post_init__(self):
467
453
# register exception handlers
468
454
add_exception_handlers (self .app , status_codes = self .exceptions )
469
455
470
- # customize openapi
471
- self .app .openapi = self .customize_openapi
472
-
473
456
# add middlewares
474
457
if self .middlewares and self .app .middleware_stack is not None :
475
458
raise RuntimeError ("Cannot add middleware after an application has started" )
0 commit comments