Skip to content

Commit

Permalink
Allow to disable doc endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarolopez committed Jul 13, 2023
1 parent fd7a31f commit 2d34375
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion deepaas/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

async def get_app(
swagger=True,
enable_doc=True,
doc="/ui",
prefix="",
static_path="/static/swagger",
Expand Down Expand Up @@ -101,7 +102,7 @@ async def get_app(
basePath=base_path,
version=deepaas.__version__,
url="/swagger.json",
swagger_path=doc if doc else None,
swagger_path=doc if enable_doc else None,
prefix=prefix,
static_path=static_path,
in_place=True,
Expand Down
2 changes: 1 addition & 1 deletion deepaas/cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def main():
log.info("Starting DEEPaaS version %s", deepaas.__version__)

app = api.get_app(
doc="/ui",
enable_doc=CONF.doc_endpoint,
enable_train=CONF.train_endpoint,
enable_predict=CONF.predict_endpoint,
)
Expand Down
8 changes: 8 additions & 0 deletions deepaas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
print to the standard output and error (i.e. stdout and stderr) through the
"/debug" endpoint. Default is to not provide this information. This will not
provide logging information about the API itself.
""",
),
cfg.BoolOpt(
"doc-endpoint",
default=True,
help="""
Enable documentation endpoint. If set we will provide the documentation
through the "/ui" endpoint. Default is to provide this information.
""",
),
cfg.IntOpt(
Expand Down
27 changes: 27 additions & 0 deletions deepaas/tests/test_v2_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ async def test_get_metadata(self):
self.assertDictEqual(meta["models"][0], await ret.json())


class TestApiV2NoDoc(base.TestCase):
async def get_application(self):
app = web.Application(debug=True)
app.middlewares.append(web.normalize_path_middleware())

deepaas.model.v2.register_models(app)

v2app = v2.get_app(enable_doc=False)
app.add_subapp("/v2", v2app)

return app

def setUp(self):
super(TestApiV2NoDoc, self).setUp()

self.maxDiff = None

self.flags(debug=True)

def assert_ok(self, response):
self.assertIn(response.status, [200, 201])

async def test_not_found(self):
ret = await self.client.get("/ui")
self.assertEqual(404, ret.status)


class TestApiV2(base.TestCase):
async def get_application(self):
app = web.Application(debug=True)
Expand Down

0 comments on commit 2d34375

Please sign in to comment.