Skip to content

Commit

Permalink
feat(api): add swagger support at the root of the API
Browse files Browse the repository at this point in the history
Content Type for it is application/openapi+json or ?format=openapi

Closes deis#811
  • Loading branch information
helgi committed Oct 4, 2016
1 parent 9f6cb94 commit d99c894
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions rootfs/api/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
'jsonfield',
'rest_framework',
'rest_framework.authtoken',
'rest_framework_swagger',
# Deis apps
'api'
)
Expand Down Expand Up @@ -161,6 +162,15 @@
'EXCEPTION_HANDLER': 'api.exceptions.custom_exception_handler'
}

# SWAGGER_SETTINGS = {
# 'SECURITY_DEFINITIONS': {
# 'basic': {
# 'type': 'apiKey'
# }
# },
# }


# URLs that end with slashes are ugly
APPEND_SLASH = False

Expand Down
12 changes: 12 additions & 0 deletions rootfs/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
from rest_framework import mixins, renderers, status
from rest_framework.exceptions import PermissionDenied, NotFound, AuthenticationFailed
from rest_framework.permissions import IsAuthenticated
from rest_framework.schemas import SchemaGenerator
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from rest_framework.authtoken.models import Token
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import CoreJSONRenderer
from rest_framework_swagger.renderers import OpenAPIRenderer

from api import authentication, models, permissions, serializers, viewsets
from api.models import AlreadyExists, ServiceUnavailable, DeisException, UnprocessableEntity
Expand All @@ -23,6 +27,13 @@
logger = logging.getLogger(__name__)


@api_view()
@renderer_classes([OpenAPIRenderer, CoreJSONRenderer])
def schema_view(request):
generator = SchemaGenerator(title='Deis Workflow Controller API')
return Response(generator.get_schema(request=request))


class ReadinessCheckView(View):
"""
Simple readiness check view to determine DB connection / query.
Expand Down Expand Up @@ -543,6 +554,7 @@ class AppPermsViewSet(BaseDeisViewSet):
"""RESTful views for sharing apps with collaborators."""

model = models.App # models class
serializer_class = serializers.UserSerializer
perm = 'use_app' # short name for permission

def get_queryset(self):
Expand Down
4 changes: 2 additions & 2 deletions rootfs/deis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


from django.conf.urls import include, url
from api.views import LivenessCheckView
from api.views import ReadinessCheckView
from api.views import LivenessCheckView, ReadinessCheckView, schema_view

urlpatterns = [
url('^$', schema_view),
url(r'^healthz$', LivenessCheckView.as_view()),
url(r'^readiness$', ReadinessCheckView.as_view()),
url(r'^v2/', include('api.urls')),
Expand Down
1 change: 1 addition & 0 deletions rootfs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Django==1.10.2
django-cors-middleware==1.3.1
django-guardian==1.4.6
djangorestframework==3.4.7
django-rest-swagger==2.0.6
docker-py==1.10.3
gunicorn==19.6.0
jmespath==0.9.0
Expand Down

0 comments on commit d99c894

Please sign in to comment.