11"""Fastapi app creation."""
22
33
4- from typing import Any , Dict , List , Optional , Tuple , Type , Union
4+ from typing import Dict , List , Optional , Tuple , Type , Union
55
66import attr
77from brotli_asgi import BrotliMiddleware
88from fastapi import APIRouter , FastAPI
9- from fastapi .openapi .utils import get_openapi
109from fastapi .params import Depends
1110from stac_pydantic import api
1211from stac_pydantic .api .collections import Collections
@@ -71,19 +70,6 @@ class StacApi:
7170 exceptions : Dict [Type [Exception ], int ] = attr .ib (
7271 default = attr .Factory (lambda : DEFAULT_STATUS_CODES )
7372 )
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 ))
8773 title : str = attr .ib (
8874 default = attr .Factory (
8975 lambda self : self .settings .stac_fastapi_title , takes_self = True
@@ -100,6 +86,22 @@ class StacApi:
10086 lambda self : self .settings .stac_fastapi_description , takes_self = True
10187 )
10288 )
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 ))
103105 search_get_request_model : Type [BaseSearchGetRequest ] = attr .ib (
104106 default = BaseSearchGetRequest
105107 )
@@ -388,22 +390,6 @@ def register_core(self):
388390 self .register_get_collection ()
389391 self .register_get_item_collection ()
390392
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-
407393 def add_health_check (self ):
408394 """Add a health check."""
409395 mgmt_router = APIRouter (prefix = self .app .state .router_prefix )
@@ -467,9 +453,6 @@ def __attrs_post_init__(self):
467453 # register exception handlers
468454 add_exception_handlers (self .app , status_codes = self .exceptions )
469455
470- # customize openapi
471- self .app .openapi = self .customize_openapi
472-
473456 # add middlewares
474457 if self .middlewares and self .app .middleware_stack is not None :
475458 raise RuntimeError ("Cannot add middleware after an application has started" )
0 commit comments