1
0
mirror of https://github.com/daniviga/bite.git synced 2025-04-20 14:31:20 +02:00

Add swagger ui

This commit is contained in:
Daniele Viganò 2020-06-26 17:41:46 +02:00
parent b15b88aab4
commit 6970a7c95b
Signed by: dani
GPG Key ID: DB49AFC03C40EE02
3 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Swagger</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist@3/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
<script>
const ui = SwaggerUIBundle({
url: "{% url schema_url %}",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
layout: "BaseLayout"
})
</script>
</body>
</html>

View File

@ -34,6 +34,7 @@ Including another URLconf
"""
from django.contrib import admin
from django.conf import settings
from django.urls import include, path
from api import urls as api_urls
@ -45,3 +46,19 @@ urlpatterns = [
path('api/', include(api_urls)),
path('telemetry/', include(telemetry_urls)),
]
if settings.DEBUG:
from django.views.generic import TemplateView
from rest_framework.schemas import get_schema_view
urlpatterns += [
path('swagger/', TemplateView.as_view(
template_name='swagger.html',
extra_context={'schema_url': 'openapi-schema'}
), name='swagger'),
path('openapi', get_schema_view(
title="BITE - A Basic/IoT/Example",
description="BITE API for IoT",
version="1.0.0"
), name='openapi-schema'),
]

View File

@ -4,5 +4,7 @@ django-health-check
psycopg2-binary
paho-mqtt==1.5.0
asyncio-mqtt==0.5.0
PyYAML
uritemplate
pygments
gunicorn