Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strawman API Docs #1419

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
13 changes: 13 additions & 0 deletions jupyter_server/services/api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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),
Expand Down
27 changes: 27 additions & 0 deletions jupyter_server/templates/apidocs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "page.html" %}

{% block stylesheet %}
{{ super() }}
<link rel="stylesheet" href="{{ static_url('vendor/swagger-ui-dist/swagger-ui.css') }}" />
<style>
.swagger-ui .info .title small pre {
background-color: transparent;
border: 0;
}
</style>
{% endblock stylesheet %}

{% block site %}
<div id="swagger-ui"></div>
{% endblock site %}

{% block script %}
{{ super() }}
<script src="{{ static_url('vendor/swagger-ui-dist/swagger-ui-bundle.js') }}"></script>

<script>
;(function(){
SwaggerUIBundle({ url: "./spec.yaml", dom_id: "#swagger-ui" });
}).call(this);
</script>
{% endblock script %}
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,swagger-ui.css,swagger-ui-bundle.js}\" jupyter_server/static/vendor/swagger-ui-dist"
},
"dependencies": {
"bootstrap": "^3.4.0",
"copyfiles": "^2.4.1"
"copyfiles": "^2.4.1",
"swagger-ui-dist": "^5.17.2"
},
"eslintIgnore": [
"*.min.js",
Expand Down
16 changes: 13 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,26 @@ 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"]
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/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.css",
]
skip-if-exists = ["jupyter_server/static/style/bootstrap.min.css"]
install-pre-commit-hook = true
optional-editable-build = true

Expand Down
5 changes: 5 additions & 0 deletions tests/services/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down