@@ -39,14 +39,23 @@ class FastAPIConfig(
39
39
CorsConfig , HealthChecksConfig , LoggingConfig , OpentelemetryConfig , PrometheusConfig , SentryConfig , SwaggerConfig
40
40
):
41
41
application : "fastapi.FastAPI" = dataclasses .field (default = None ) # type: ignore[assignment]
42
+ application_kwargs : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
42
43
opentelemetry_excluded_urls : list [str ] = dataclasses .field (default_factory = list )
43
44
prometheus_instrumentator_params : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
44
45
prometheus_instrument_params : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
45
46
prometheus_expose_params : dict [str , typing .Any ] = dataclasses .field (default_factory = dict )
46
47
47
48
def __post_init__ (self ) -> None :
48
49
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
50
59
51
60
52
61
@dataclasses .dataclass (kw_only = True , slots = True , frozen = True )
@@ -182,9 +191,6 @@ async def lifespan_manager(self, _: "fastapi.FastAPI") -> typing.AsyncIterator[d
182
191
183
192
def __init__ (self , bootstrap_config : FastAPIConfig ) -> None :
184
193
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
188
194
189
195
old_lifespan_manager = self .bootstrap_config .application .router .lifespan_context
190
196
self .bootstrap_config .application .router .lifespan_context = _merge_lifespan_context (
0 commit comments