From 7d585b6eaef721abc115dfb40851cf9912538c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santos?= Date: Sun, 14 May 2023 14:18:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(spectree):=20remove=20unnece?= =?UTF-8?q?ssary=20app=20attribute=20from=20backend=20The=20app=20attribut?= =?UTF-8?q?e=20was=20being=20set=20in=20the=20backend,=20but=20it=20was=20?= =?UTF-8?q?not=20being=20used.=20This=20commit=20removes=20the=20app=20att?= =?UTF-8?q?ribute=20from=20the=20backend.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spectree/plugins/falcon_plugin.py | 7 +++---- spectree/plugins/starlette_plugin.py | 8 +++----- spectree/spec.py | 2 -- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/spectree/plugins/falcon_plugin.py b/spectree/plugins/falcon_plugin.py index 892661eb..8539f0b7 100644 --- a/spectree/plugins/falcon_plugin.py +++ b/spectree/plugins/falcon_plugin.py @@ -70,12 +70,11 @@ def __init__(self, spectree): self.INT_ARGS_NAMES = ("num_digits", "min", "max") def register_route(self, app: Any): - self.app = app - self.app.add_route( + app.add_route( self.config.spec_url, self.OPEN_API_ROUTE_CLASS(self.spectree.spec) ) for ui in self.config.page_templates: - self.app.add_route( + app.add_route( f"/{self.config.path}/{ui}", self.DOC_PAGE_ROUTE_CLASS( self.config.page_templates[ui], @@ -95,7 +94,7 @@ def find_node(node): for child in node.children: find_node(child) - for route in self.app._router._roots: + for route in self.spectree.app._router._roots: find_node(route) return routes diff --git a/spectree/plugins/starlette_plugin.py b/spectree/plugins/starlette_plugin.py index f0ef2226..c9d0c391 100644 --- a/spectree/plugins/starlette_plugin.py +++ b/spectree/plugins/starlette_plugin.py @@ -36,15 +36,13 @@ def __init__(self, spectree): self.conv2type = {conv: typ for typ, conv in CONVERTOR_TYPES.items()} def register_route(self, app): - self.app = app - - self.app.add_route( + app.add_route( self.config.spec_url, lambda request: JSONResponse(self.spectree.spec), ) for ui in self.config.page_templates: - self.app.add_route( + app.add_route( f"/{self.config.path}/{ui}", lambda request, ui=ui: HTMLResponse( self.config.page_templates[ui].format( @@ -177,7 +175,7 @@ def parse_route(app, prefix=""): else: parse_route(route, prefix=f"{prefix}{route.path}") - parse_route(self.app) + parse_route(self.spectree.app) return routes def bypass(self, func, method): diff --git a/spectree/spec.py b/spectree/spec.py index af43207c..fc0a172c 100644 --- a/spectree/spec.py +++ b/spectree/spec.py @@ -99,8 +99,6 @@ def register(self, app: Any): self.app = app if self.publish_apidoc: self.backend.register_route(self.app) - else: - self.backend.app = self.app @property def spec(self):