Skip to content

Commit

Permalink
feat: change swagger URL from /ui to /api
Browse files Browse the repository at this point in the history
Some users got confused about the /ui endpoint being a full endpoint,
when it is not, lets move /ui to /api instead.

fixes: #131
  • Loading branch information
alvarolopez committed Mar 8, 2024
1 parent 5b0bb27 commit 8ea19bc
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deepaas/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
async def get_app(
swagger=True,
enable_doc=True,
doc="/ui",
doc="/api",
prefix="",
static_path="/static/swagger",
base_path="",
Expand Down
6 changes: 6 additions & 0 deletions deepaas/api/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deepaas/cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deepaas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions deepaas/tests/fake_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
],
}
Expand All @@ -59,15 +59,15 @@
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"},
],
}

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"},
],
}
Expand Down
2 changes: 1 addition & 1 deletion deepaas/tests/test_v2_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion deepaas/tests/test_versions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ea19bc

Please sign in to comment.