Skip to content

Commit

Permalink
rest: add API schema
Browse files Browse the repository at this point in the history
Now, the REST API is exposing a schema endpoint at /api/v1/schema/.
This makes it possible to dynamically interact with API through
the coreapi command line tool.

Message-Id: <20180308162213.5193-1-shubhamjain7495@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
shubhamdotjain authored and bonzini committed Mar 8, 2018
1 parent f020fcd commit 647174a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/urls.py
Expand Up @@ -11,6 +11,7 @@
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter
from rest_framework_nested.routers import NestedDefaultRouter
from rest_framework.schemas import get_schema_view

from . import views
from . import rest
Expand All @@ -36,9 +37,12 @@ def _build_urls(base=None, r=[]):
projects_router.register('series', rest.ProjectSeriesViewSet, base_name='series')
projects_router.register('messages', rest.MessagesViewSet, base_name='messages')

schema_view = get_schema_view(title='API schema')

urlpatterns = _build_urls() + [
url(r"v1/", include(router.urls)),
url(r"v1/", include(projects_router.urls)),
url(r'^v1/schema/$', schema_view),
# Use the base class's handler by default
url(r".*", views.APIView.as_view())
]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -5,3 +5,4 @@ django-debug-toolbar==1.8
gunicorn>=19
djangorestframework>=3.0.0
drf-nested-routers
coreapi-cli

0 comments on commit 647174a

Please sign in to comment.