[Patchew-devel] [PATCH] rest: add API schema

Shubham Jain posted 1 patch 6 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20180308162213.5193-1-shubhamjain7495@gmail.com
api/urls.py      | 4 ++++
requirements.txt | 1 +
2 files changed, 5 insertions(+)
[Patchew-devel] [PATCH] rest: add API schema
Posted by Shubham Jain 6 years, 9 months ago
   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.
---
 api/urls.py      | 4 ++++
 requirements.txt | 1 +
 2 files changed, 5 insertions(+)

diff --git a/api/urls.py b/api/urls.py
index 3a8a66d..0a447f0 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -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
@@ -36,9 +37,12 @@ projects_router.include_format_suffixes = False
 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())
     ]
diff --git a/requirements.txt b/requirements.txt
index 9fb9c57..252f226 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,3 +5,4 @@ django-debug-toolbar==1.8
 gunicorn>=19
 djangorestframework>=3.0.0
 drf-nested-routers
+coreapi-cli
\ No newline at end of file
-- 
2.14.3 (Apple Git-98)

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel