From 2eece4f458297a52bd4e1952e5cae5a56369d9c6 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Thu, 2 May 2024 18:55:14 -0500 Subject: [PATCH 1/7] gh-1418: swagger-ui-dist strawman --- .gitignore | 1 + jupyter_server/services/api/handlers.py | 13 ++++++++++++ jupyter_server/templates/apidocs.html | 27 +++++++++++++++++++++++++ package-lock.json | 13 +++++++++++- package.json | 7 +++++-- pyproject.toml | 11 ++++++++-- tests/base/test_handlers.py | 10 +++++++++ 7 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 jupyter_server/templates/apidocs.html diff --git a/.gitignore b/.gitignore index 04ef5c46fa..5cab6cc5c7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ docs/gh-pages jupyter_server/i18n/*/LC_MESSAGES/*.mo jupyter_server/i18n/*/LC_MESSAGES/nbjs.json jupyter_server/static/style/*.min.css* +jupyter_server/static/vendor/ node_modules *.py[co] __pycache__ diff --git a/jupyter_server/services/api/handlers.py b/jupyter_server/services/api/handlers.py index 22904fdb07..3d2703ea88 100644 --- a/jupyter_server/services/api/handlers.py +++ b/jupyter_server/services/api/handlers.py @@ -43,6 +43,18 @@ def get_content_type(self): return "text/x-yaml" +class APIDocsHandler(JupyterHandler): + """A handler for the documentation of the REST API.""" + + auth_resource = AUTH_RESOURCE + + @web.authenticated + @authorized + async def get(self): + """Get the REST API documentation.""" + return self.finish(self.render_template("apidocs.html")) + + class APIStatusHandler(APIHandler): """An API status handler.""" @@ -115,6 +127,7 @@ async def get(self): default_handlers = [ + (r"/api/apidocs", APIDocsHandler), (r"/api/spec.yaml", APISpecHandler), (r"/api/status", APIStatusHandler), (r"/api/me", IdentityHandler), diff --git a/jupyter_server/templates/apidocs.html b/jupyter_server/templates/apidocs.html new file mode 100644 index 0000000000..9d4e761935 --- /dev/null +++ b/jupyter_server/templates/apidocs.html @@ -0,0 +1,27 @@ +{% extends "page.html" %} + +{% block stylesheet %} + {{ super() }} + + +{% endblock stylesheet %} + +{% block site %} +
+{% endblock site %} + +{% block script %} + {{ super() }} + + + +{% endblock script %} diff --git a/package-lock.json b/package-lock.json index 546528db85..d34b816d1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "BSD", "dependencies": { "bootstrap": "^3.4.0", - "copyfiles": "^2.4.1" + "copyfiles": "^2.4.1", + "swagger-ui-dist": "^5.17.2" } }, "node_modules/ansi-regex": { @@ -288,6 +289,11 @@ "node": ">=8" } }, + "node_modules/swagger-ui-dist": { + "version": "5.17.2", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.17.2.tgz", + "integrity": "sha512-V/NqUw6QoTrjSpctp2oLQvxrl3vW29UsUtZyq7B1CF0v870KOFbYGDQw8rpKaKm0JxTwHpWnW1SN9YuKZdiCyw==" + }, "node_modules/through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -621,6 +627,11 @@ "ansi-regex": "^5.0.0" } }, + "swagger-ui-dist": { + "version": "5.17.2", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.17.2.tgz", + "integrity": "sha512-V/NqUw6QoTrjSpctp2oLQvxrl3vW29UsUtZyq7B1CF0v870KOFbYGDQw8rpKaKm0JxTwHpWnW1SN9YuKZdiCyw==" + }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", diff --git a/package.json b/package.json index 78c0dce49a..139b1a91b3 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,14 @@ "version": "1.0.0", "license": "BSD", "scripts": { - "build": "copyfiles -f node_modules/bootstrap/dist/css/*.min.* jupyter_server/static/style" + "build": "npm run build:bootstrap && npm run build:swagger-ui", + "build:bootstrap": "copyfiles -f node_modules/bootstrap/dist/css/*.min.* jupyter_server/static/style", + "build:swagger-ui": "copyfiles -f \"node_modules/swagger-ui-dist/{NOTICE,LICENSE}\" \"node_modules/swagger-ui-dist/swagger-ui{.css,-bundle.js}\" jupyter_server/static/vendor/swagger-ui" }, "dependencies": { "bootstrap": "^3.4.0", - "copyfiles": "^2.4.1" + "copyfiles": "^2.4.1", + "swagger-ui-dist": "^5.17.2" }, "eslintIgnore": [ "*.min.js", diff --git a/pyproject.toml b/pyproject.toml index 42350ed474..f4908ad99b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,9 +133,16 @@ dependencies = ["hatch-jupyter-builder>=0.8.1"] build-function = "hatch_jupyter_builder.npm_builder" ensured-targets = [ "jupyter_server/static/style/bootstrap.min.css", - "jupyter_server/static/style/bootstrap-theme.min.css" + "jupyter_server/static/style/bootstrap-theme.min.css", + "jupyter_server/static/vendor/swagger-ui/dist/dist/swagger-ui.css", + "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui-bundle.js", + "jupyter_server/static/vendor/swagger-ui/LICENSE", + "jupyter_server/static/vendor/swagger-ui/NOTICE", +] +skip-if-exists = [ + "jupyter_server/static/style/bootstrap.min.css", + "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui-bundle.js", ] -skip-if-exists = ["jupyter_server/static/style/bootstrap.min.css"] install-pre-commit-hook = true optional-editable-build = true diff --git a/tests/base/test_handlers.py b/tests/base/test_handlers.py index 6d8dce90da..6ef460c484 100644 --- a/tests/base/test_handlers.py +++ b/tests/base/test_handlers.py @@ -13,6 +13,7 @@ from jupyter_server.auth.decorator import allow_unauthenticated from jupyter_server.base.handlers import ( APIHandler, + APIDocsHandler, APIVersionHandler, AuthenticatedFileHandler, AuthenticatedHandler, @@ -238,6 +239,15 @@ async def test_api_version_handler(jp_serverapp): assert handler.get_status() == 200 +async def test_api_docs_handler(jp_serverapp): + app: ServerApp = jp_serverapp + request = HTTPRequest("GET") + request.connection = MagicMock() + handler = APIDocsHandler(app.web_app, request) + handler.get() + assert handler.get_status() == 200 + + async def test_files_redirect_handler(jp_serverapp): app: ServerApp = jp_serverapp request = HTTPRequest("GET") From 0d1ddf06974ec0b05bdafada97a736adbd728ae3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 00:15:20 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/base/test_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/base/test_handlers.py b/tests/base/test_handlers.py index 6ef460c484..7075e9c0fe 100644 --- a/tests/base/test_handlers.py +++ b/tests/base/test_handlers.py @@ -12,8 +12,8 @@ from jupyter_server.auth import AllowAllAuthorizer, IdentityProvider, User from jupyter_server.auth.decorator import allow_unauthenticated from jupyter_server.base.handlers import ( - APIHandler, APIDocsHandler, + APIHandler, APIVersionHandler, AuthenticatedFileHandler, AuthenticatedHandler, From 572049cdef54fb24e4d951d6d572690d39ad5b25 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Thu, 2 May 2024 19:29:36 -0500 Subject: [PATCH 3/7] fix test import --- tests/base/test_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/base/test_handlers.py b/tests/base/test_handlers.py index 7075e9c0fe..f0b54e18c2 100644 --- a/tests/base/test_handlers.py +++ b/tests/base/test_handlers.py @@ -12,7 +12,6 @@ from jupyter_server.auth import AllowAllAuthorizer, IdentityProvider, User from jupyter_server.auth.decorator import allow_unauthenticated from jupyter_server.base.handlers import ( - APIDocsHandler, APIHandler, APIVersionHandler, AuthenticatedFileHandler, @@ -23,6 +22,7 @@ RedirectWithParams, ) from jupyter_server.serverapp import ServerApp +from jupyter_server.services.api.handlers import APIDocsHandler from jupyter_server.utils import url_path_join From 5d92576a0c040baafb361b5d5fb6756c87e47925 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Thu, 2 May 2024 20:18:48 -0500 Subject: [PATCH 4/7] move test --- tests/base/test_handlers.py | 10 ---------- tests/services/api/test_api.py | 5 +++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/base/test_handlers.py b/tests/base/test_handlers.py index f0b54e18c2..6d8dce90da 100644 --- a/tests/base/test_handlers.py +++ b/tests/base/test_handlers.py @@ -22,7 +22,6 @@ RedirectWithParams, ) from jupyter_server.serverapp import ServerApp -from jupyter_server.services.api.handlers import APIDocsHandler from jupyter_server.utils import url_path_join @@ -239,15 +238,6 @@ async def test_api_version_handler(jp_serverapp): assert handler.get_status() == 200 -async def test_api_docs_handler(jp_serverapp): - app: ServerApp = jp_serverapp - request = HTTPRequest("GET") - request.connection = MagicMock() - handler = APIDocsHandler(app.web_app, request) - handler.get() - assert handler.get_status() == 200 - - async def test_files_redirect_handler(jp_serverapp): app: ServerApp = jp_serverapp request = HTTPRequest("GET") diff --git a/tests/services/api/test_api.py b/tests/services/api/test_api.py index f013dcfcd8..1a1115e18f 100644 --- a/tests/services/api/test_api.py +++ b/tests/services/api/test_api.py @@ -13,6 +13,11 @@ async def test_get_spec(jp_fetch): assert response.code == 200 +async def test_get_api_docs(jp_fetch): + response = await jp_fetch("api", "apidocs", method="GET") + assert response.code == 200 + + async def test_get_status(jp_fetch): response = await jp_fetch("api", "status", method="GET") assert response.code == 200 From 995f13b0f733b64b858b50c9ccb5014de1e368ed Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Thu, 2 May 2024 20:35:49 -0500 Subject: [PATCH 5/7] dedupe dist --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f4908ad99b..bc2086fcb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -134,7 +134,7 @@ build-function = "hatch_jupyter_builder.npm_builder" ensured-targets = [ "jupyter_server/static/style/bootstrap.min.css", "jupyter_server/static/style/bootstrap-theme.min.css", - "jupyter_server/static/vendor/swagger-ui/dist/dist/swagger-ui.css", + "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui.css", "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui-bundle.js", "jupyter_server/static/vendor/swagger-ui/LICENSE", "jupyter_server/static/vendor/swagger-ui/NOTICE", From 53fb9e10d5184160d2dfa7b2d62fb71c58b0a69d Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Fri, 3 May 2024 08:00:06 -0500 Subject: [PATCH 6/7] fix dist --- package.json | 2 +- pyproject.toml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 139b1a91b3..87d7309e14 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "npm run build:bootstrap && npm run build:swagger-ui", "build:bootstrap": "copyfiles -f node_modules/bootstrap/dist/css/*.min.* jupyter_server/static/style", - "build:swagger-ui": "copyfiles -f \"node_modules/swagger-ui-dist/{NOTICE,LICENSE}\" \"node_modules/swagger-ui-dist/swagger-ui{.css,-bundle.js}\" jupyter_server/static/vendor/swagger-ui" + "build:swagger-ui": "copyfiles -f \"node_modules/swagger-ui-dist/{NOTICE,LICENSE,swagger-ui.css,swagger-ui-bundle.js}\" jupyter_server/static/vendor/swagger-ui-dist" }, "dependencies": { "bootstrap": "^3.4.0", diff --git a/pyproject.toml b/pyproject.toml index bc2086fcb4..4e4e014ab3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -134,14 +134,14 @@ build-function = "hatch_jupyter_builder.npm_builder" ensured-targets = [ "jupyter_server/static/style/bootstrap.min.css", "jupyter_server/static/style/bootstrap-theme.min.css", - "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui.css", - "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui-bundle.js", - "jupyter_server/static/vendor/swagger-ui/LICENSE", - "jupyter_server/static/vendor/swagger-ui/NOTICE", + "jupyter_server/static/vendor/swagger-ui-dist/LICENSE", + "jupyter_server/static/vendor/swagger-ui-dist/NOTICE", + "jupyter_server/static/vendor/swagger-ui-dist/swagger-ui-bundle.js", + "jupyter_server/static/vendor/swagger-ui-dist/swagger-ui.css", ] skip-if-exists = [ "jupyter_server/static/style/bootstrap.min.css", - "jupyter_server/static/vendor/swagger-ui/dist/swagger-ui-bundle.js", + "jupyter_server/static/vendor/swagger-ui-dist/swagger-ui.css", ] install-pre-commit-hook = true optional-editable-build = true From 081ad10a24ca6ef3fb12d42c52e18c79826fa276 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Fri, 3 May 2024 08:18:15 -0500 Subject: [PATCH 7/7] add vendor to artifacts --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4e4e014ab3..93d8448d1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,7 +126,10 @@ path = "jupyter_server/_version.py" validate-bump = false [tool.hatch.build] -artifacts = ["jupyter_server/static/style"] +artifacts = [ + "jupyter_server/static/style", + "jupyter_server/static/vendor", +] [tool.hatch.build.hooks.jupyter-builder] dependencies = ["hatch-jupyter-builder>=0.8.1"]