@@ -39,14 +39,23 @@ class FastAPIConfig(
3939 CorsConfig , HealthChecksConfig , LoggingConfig , OpentelemetryConfig , PrometheusConfig , SentryConfig , SwaggerConfig
4040):
4141 application : "fastapi.FastAPI" = dataclasses .field (default = None ) # type: ignore[assignment]
42+ application_kwargs : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
4243 opentelemetry_excluded_urls : list [str ] = dataclasses .field (default_factory = list )
4344 prometheus_instrumentator_params : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
4445 prometheus_instrument_params : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
4546 prometheus_expose_params : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
4647
4748 def __post_init__ (self ) -> None :
4849 if not self .application :
49- object .__setattr__ (self , "application" , fastapi .FastAPI (docs_url = self .swagger_path ))
50+ object .__setattr__ (
51+ self , "application" , fastapi .FastAPI (docs_url = self .swagger_path , ** self .application_kwargs )
52+ )
53+ elif self .application_kwargs :
54+ warnings .warn ("application_kwargs must be used without application" , stacklevel = 2 )
55+
56+ self .application .title = self .service_name
57+ self .application .debug = self .service_debug
58+ self .application .version = self .service_version
5059
5160
5261@dataclasses .dataclass (kw_only = True , slots = True , frozen = True )
@@ -182,9 +191,6 @@ async def lifespan_manager(self, _: "fastapi.FastAPI") -> typing.AsyncIterator[d
182191
183192 def __init__ (self , bootstrap_config : FastAPIConfig ) -> None :
184193 super ().__init__ (bootstrap_config )
185- self .bootstrap_config .application .title = bootstrap_config .service_name
186- self .bootstrap_config .application .debug = bootstrap_config .service_debug
187- self .bootstrap_config .application .version = bootstrap_config .service_version
188194
189195 old_lifespan_manager = self .bootstrap_config .application .router .lifespan_context
190196 self .bootstrap_config .application .router .lifespan_context = _merge_lifespan_context (
0 commit comments