From 8ea19bcd5bcdc9e3174a9202b7bea2858485fb4f Mon Sep 17 00:00:00 2001 From: Alvaro Lopez Garcia Date: Mon, 8 Jan 2024 11:02:00 +0100 Subject: [PATCH] feat: change swagger URL from /ui to /api Some users got confused about the /ui endpoint being a full endpoint, when it is not, lets move /ui to /api instead. fixes: #131 --- deepaas/api/__init__.py | 2 +- deepaas/api/versions.py | 6 ++++++ deepaas/cmd/run.py | 2 +- deepaas/config.py | 2 +- deepaas/tests/fake_responses.py | 6 +++--- deepaas/tests/test_v2_api.py | 2 +- deepaas/tests/test_versions_api.py | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/deepaas/api/__init__.py b/deepaas/api/__init__.py index eb1cd738..3c45713e 100644 --- a/deepaas/api/__init__.py +++ b/deepaas/api/__init__.py @@ -55,7 +55,7 @@ async def get_app( swagger=True, enable_doc=True, - doc="/ui", + doc="/api", prefix="", static_path="/static/swagger", base_path="", diff --git a/deepaas/api/versions.py b/deepaas/api/versions.py index c5ce8dfd..d6241533 100644 --- a/deepaas/api/versions.py +++ b/deepaas/api/versions.py @@ -63,6 +63,12 @@ async def get(self): return web.json_response(response) +@routes.get("/ui") +async def redirect_ui(request): + doc_url = request.app.router.named_resources().get("swagger.docs").url_for() + return web.HTTPFound(doc_url) + + def register_version(version, func): # NOTE(aloga): we could use a @classmethod on Versions, but it fails # with a TypeError: 'classmethod' object is not callable since the function diff --git a/deepaas/cmd/run.py b/deepaas/cmd/run.py index b68e46b8..b5532224 100644 --- a/deepaas/cmd/run.py +++ b/deepaas/cmd/run.py @@ -83,7 +83,7 @@ def main(): base = "http://{}:{}".format(CONF.listen_ip, CONF.listen_port) spec = "{}/swagger.json".format(base) - docs = "{}/ui".format(base) + docs = "{}/api".format(base) v2 = "{}/v2".format(base) print(INTRO) diff --git a/deepaas/config.py b/deepaas/config.py index 18b079a0..f87a2c18 100644 --- a/deepaas/config.py +++ b/deepaas/config.py @@ -55,7 +55,7 @@ default=True, help=""" Enable documentation endpoint. If set we will provide the documentation -through the "/ui" endpoint. Default is to provide this information. +through the "/api" endpoint. Default is to provide this information. """, ), cfg.IntOpt( diff --git a/deepaas/tests/fake_responses.py b/deepaas/tests/fake_responses.py index 4e2a2ca3..7512655e 100644 --- a/deepaas/tests/fake_responses.py +++ b/deepaas/tests/fake_responses.py @@ -49,7 +49,7 @@ v2_version, ], "links": [ - {"rel": "help", "type": "text/html", "href": "/ui"}, + {"rel": "help", "type": "text/html", "href": "/api"}, {"rel": "describedby", "type": "application/json", "href": "/swagger.json"}, ], } @@ -59,7 +59,7 @@ v2_version, ], "links": [ - {"rel": "help", "type": "text/html", "href": "/ui"}, + {"rel": "help", "type": "text/html", "href": "/api"}, {"rel": "describedby", "type": "application/json", "href": "/swagger.json"}, ], } @@ -67,7 +67,7 @@ empty_versions = { "versions": [], "links": [ - {"rel": "help", "type": "text/html", "href": "/ui"}, + {"rel": "help", "type": "text/html", "href": "/api"}, {"rel": "describedby", "type": "application/json", "href": "/swagger.json"}, ], } diff --git a/deepaas/tests/test_v2_api.py b/deepaas/tests/test_v2_api.py index e7d90dc5..7ad89df4 100644 --- a/deepaas/tests/test_v2_api.py +++ b/deepaas/tests/test_v2_api.py @@ -160,7 +160,7 @@ def assert_ok(self, response): self.assertIn(response.status, [200, 201]) async def test_not_found(self): - ret = await self.client.get("/ui") + ret = await self.client.get("/api") self.assertEqual(404, ret.status) diff --git a/deepaas/tests/test_versions_api.py b/deepaas/tests/test_versions_api.py index 0e3ca3b8..3d192d1f 100644 --- a/deepaas/tests/test_versions_api.py +++ b/deepaas/tests/test_versions_api.py @@ -34,7 +34,7 @@ async def get_application(self): versions.Versions.versions = {} aiohttp_apispec.setup_aiohttp_apispec( - app=app, url="/swagger.json", swagger_path="/ui" + app=app, url="/swagger.json", swagger_path="/api" ) return app