|
8 | 8 | from litestar.config.cors import CORSConfig as LitestarCorsConfig |
9 | 9 | from litestar.contrib.opentelemetry.config import OpenTelemetryConfig as LitestarOpentelemetryConfig |
10 | 10 | from litestar.contrib.prometheus import PrometheusConfig, PrometheusController |
| 11 | +from litestar.openapi.plugins import SwaggerRenderPlugin |
11 | 12 | from litestar_offline_docs import generate_static_files_config |
12 | 13 | from sentry_sdk.integrations.litestar import LitestarIntegration |
13 | 14 |
|
@@ -51,24 +52,30 @@ def bootstrap(self) -> None: |
51 | 52 | @LitestarBootstrapper.use_instrument() |
52 | 53 | class LitestarSwaggerInstrument(SwaggerInstrument): |
53 | 54 | def bootstrap_before(self) -> dict[str, typing.Any]: |
54 | | - class LitestarOpenAPIController(openapi.OpenAPIController): |
55 | | - path = self.instrument_config.swagger_path |
56 | | - if self.instrument_config.swagger_offline_docs: |
57 | | - swagger_ui_standalone_preset_js_url = ( |
58 | | - f"{self.instrument_config.service_static_path}/swagger-ui-standalone-preset.js" |
59 | | - ) |
60 | | - swagger_bundle_path: str = f"{self.instrument_config.service_static_path}/swagger-ui-bundle.js" |
61 | | - swagger_css_url: str = f"{self.instrument_config.service_static_path}/swagger-ui.css" |
| 55 | + render_plugins: typing.Final = ( |
| 56 | + ( |
| 57 | + SwaggerRenderPlugin( |
| 58 | + js_url=f"{self.instrument_config.service_static_path}/swagger-ui-bundle.js", |
| 59 | + css_url=f"{self.instrument_config.service_static_path}/swagger-ui.css", |
| 60 | + standalone_preset_js_url=( |
| 61 | + f"{self.instrument_config.service_static_path}/swagger-ui-standalone-preset.js" |
| 62 | + ), |
| 63 | + ), |
| 64 | + ) |
| 65 | + if self.instrument_config.swagger_offline_docs |
| 66 | + else () |
| 67 | + ) |
62 | 68 |
|
63 | 69 | openapi_config: typing.Final = openapi.OpenAPIConfig( |
| 70 | + path=self.instrument_config.swagger_path, |
64 | 71 | title=self.instrument_config.service_name, |
65 | 72 | version=self.instrument_config.service_version, |
66 | 73 | description=self.instrument_config.service_description, |
67 | | - openapi_controller=LitestarOpenAPIController, |
| 74 | + render_plugins=render_plugins, |
68 | 75 | **self.instrument_config.swagger_extra_params, |
69 | 76 | ) |
70 | 77 |
|
71 | | - bootstrap_result = {} |
| 78 | + bootstrap_result: typing.Final = {} |
72 | 79 | if self.instrument_config.swagger_offline_docs: |
73 | 80 | bootstrap_result["static_files_config"] = [ |
74 | 81 | generate_static_files_config(static_files_handler_path=self.instrument_config.service_static_path), |
|
0 commit comments