File tree Expand file tree Collapse file tree
lib/dl_app_api_base/dl_app_api_base Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -211,12 +211,12 @@ async def _get_aiohttp_subsystem_readiness_callbacks(
211211 async def _setup_openapi (self , app : aiohttp .web .Application ) -> None :
212212 open_api_spec = await self ._get_aiohttp_open_api_spec ()
213213 open_api_handler = openapi .OpenApiHandler (raw_spec = open_api_spec .raw )
214- app .router .add_route ("GET" , self .settings .OPEN_API .spec_path , open_api_handler .process )
214+ app .router .add_route ("GET" , self .settings .OPEN_API .SPEC_PATH , open_api_handler .process )
215215
216216 if self .settings .OPEN_API .SWAGGER_UI_ENABLED :
217217 swagger_handler = openapi .SwaggerHandler .from_dependencies (
218218 openapi .SwaggerHandlerDependencies (
219- url_prefix = self .settings .OPEN_API .DOCS_PATH ,
219+ url_prefix = self .settings .OPEN_API .EXTERNAL_DOCS_PATH ,
220220 config_url = self .settings .OPEN_API .SPEC_REL_URL ,
221221 )
222222 )
@@ -229,4 +229,7 @@ async def _get_aiohttp_open_api_spec(
229229 self ,
230230 ) -> openapi .OpenApiSpec :
231231 routes = await self ._get_aiohttp_app_routes ()
232- return openapi .OpenApiSpec (routes = routes )
232+ return openapi .OpenApiSpec (
233+ routes = routes ,
234+ external_route_prefix = self .settings .OPEN_API .EXTERNAL_ROUTE_PREFIX ,
235+ )
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class Tag:
2323 info : Info | None = None
2424 tags : list [Tag ] = attrs .field (factory = list )
2525 routes : Sequence [OpenApiRouteProtocol ] = attrs .field (factory = list )
26+ external_route_prefix : str = ""
2627
2728 @property
2829 def raw (self ) -> dict :
@@ -99,7 +100,7 @@ def raw(self) -> dict:
99100 "application/json" : {"schema" : response_schema .model_json_schema ()},
100101 },
101102 }
102- paths [route .path ][route .method .lower ()] = {
103+ paths [f" { self . external_route_prefix } { route .path } " ][route .method .lower ()] = {
103104 "tags" : route .handler .OPENAPI_TAGS ,
104105 "summary" : route .handler .OPENAPI_DESCRIPTION ,
105106 "parameters" : parameters ,
Original file line number Diff line number Diff line change 1+ import typing_extensions
2+
13import dl_settings
24
35
46class OpenApiSettings (dl_settings .BaseSettings ):
57 DOCS_PATH : str = "/api/v1/docs"
68 SPEC_REL_URL : str = "/spec.json"
79 SWAGGER_UI_ENABLED : bool = True
10+ EXTERNAL_ROUTE_PREFIX : str = ""
811
912 @property
13+ @typing_extensions .deprecated ("Use SPEC_PATH instead" , category = DeprecationWarning )
1014 def spec_path (self ) -> str :
15+ return self .SPEC_PATH
16+
17+ @property
18+ def SPEC_PATH (self ) -> str :
1119 return f"{ self .DOCS_PATH } { self .SPEC_REL_URL } "
20+
21+ @property
22+ def EXTERNAL_DOCS_PATH (self ) -> str :
23+ return f"{ self .EXTERNAL_ROUTE_PREFIX } { self .DOCS_PATH } "
You can’t perform that action at this time.
0 commit comments