From f5d167cd125c895279adaffa6878d349e8056ff0 Mon Sep 17 00:00:00 2001 From: "robin.hruska@teskalabs.com" Date: Fri, 18 Aug 2023 17:04:32 +0200 Subject: [PATCH 1/2] Configurable server URL --- asab/api/doc.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/asab/api/doc.py b/asab/api/doc.py index 9aa9f2890..fcb619529 100644 --- a/asab/api/doc.py +++ b/asab/api/doc.py @@ -40,12 +40,17 @@ def __init__(self, api_service, app, web_container, config_section_name="asab:do self.DefaultRouteTag: str = asab.Config["asab:doc"].get("default_route_tag") if self.DefaultRouteTag not in ["module_name", "class_name"]: - raise ValueError("Unknown default_route_tag: {}. Choose between options 'module_name' and 'class_name'.".format(self.DefaultRouteTag)) + raise ValueError( + "Unknown default_route_tag: {}. Choose between options " + "'module_name' and 'class_name'.".format(self.DefaultRouteTag)) + self.ServerUrl: str = asab.Config.get(config_section_name, "server_url", fallback="/") def build_swagger_documentation(self) -> dict: - """Take a docstring of the class and a docstring of methods and merge them into Swagger data.""" + """ + Take a docstring of the class and a docstring of methods and merge them into Swagger data. + """ app_doc_string: str = self.App.__doc__ app_description: str = get_description(app_doc_string) specification: dict = { @@ -60,7 +65,7 @@ def build_swagger_documentation(self) -> dict: "version": "1.0.0", }, "servers": [ - {"url": "/", "description": "Here"} + {"url": self.ServerUrl} ], # Base path relative to openapi endpoint From c13226440f56f0dd13e3c4a6f48e363fa6c3f12b Mon Sep 17 00:00:00 2001 From: "robin.hruska@teskalabs.com" Date: Fri, 18 Aug 2023 17:11:11 +0200 Subject: [PATCH 2/2] Allow multiple doc APIs --- asab/api/doc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asab/api/doc.py b/asab/api/doc.py index fcb619529..4b5f59a7e 100644 --- a/asab/api/doc.py +++ b/asab/api/doc.py @@ -44,7 +44,7 @@ def __init__(self, api_service, app, web_container, config_section_name="asab:do "Unknown default_route_tag: {}. Choose between options " "'module_name' and 'class_name'.".format(self.DefaultRouteTag)) - self.ServerUrl: str = asab.Config.get(config_section_name, "server_url", fallback="/") + self.ServerUrls: str = asab.Config.get(config_section_name, "server_urls", fallback="/").strip().split("\n") def build_swagger_documentation(self) -> dict: @@ -65,7 +65,7 @@ def build_swagger_documentation(self) -> dict: "version": "1.0.0", }, "servers": [ - {"url": self.ServerUrl} + {"url": url} for url in self.ServerUrls ], # Base path relative to openapi endpoint