Skip to content

Commit

Permalink
Implemented documentation for REST API: /api/docs/
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Manovich committed Feb 4, 2019
1 parent 2f32ed0 commit 55effe1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions cvat/apps/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT

from rest_framework import versioning

class URLPathVersioning(versioning.URLPathVersioning):
def determine_version(self, request, *args, **kwargs):
# When you try to specify a version (e.g /api/v1/docs) it will generate
# an error inside a template of Rest Framework (reverse of an URL
# without argument). Also when you try don't use version at all it will
# give you an error 'invalid version'. To avoid these problems just
# redefine determine_version for /api/docs/*.
if request.path.startswith('/api/docs/'):
return None

return super().determine_version(request, *args, **kwargs)
10 changes: 7 additions & 3 deletions cvat/apps/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.urls import path, include
from . import views
from rest_framework import routers
from rest_framework.documentation import include_docs_urls

REST_API_PREFIX = 'api/<version>/'

Expand All @@ -15,11 +16,17 @@
router.register("users", views.UserViewSet)

urlpatterns = [
# documentation for API
path('api/docs/', include_docs_urls(title='CVAT REST API')),
# entry point for API
path(REST_API_PREFIX, include(router.urls)),
# GET a frame for a specific task
path(REST_API_PREFIX + 'tasks/<int:pk>/frames/<int:frame>',
views.get_frame, name='task-frame'),
# GET meta information for all frames
path(REST_API_PREFIX + 'tasks/<int:pk>/frames/meta',
views.get_image_meta_cache, name='image-meta-cache'),

# POST an exception
path(REST_API_PREFIX + 'exceptions/', views.ClientException.as_view(),
name='exception-list'),
Expand All @@ -28,9 +35,6 @@
path( # PUT
REST_API_PREFIX + 'tasks/<int:pk>/data', views.dummy_view,
name='task-data'),
# GET meta information for all frames
path(REST_API_PREFIX + 'tasks/<int:pk>/frames/meta',
views.get_image_meta_cache, name='image-meta-cache'),



Expand Down
4 changes: 4 additions & 0 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@

# Server REST API

#class ServerViewSet(viewsets.)



class TaskViewSet(viewsets.ModelViewSet):
queryset = Task.objects.all()
serializer_class = TaskSerializer
Expand Down
2 changes: 1 addition & 1 deletion cvat/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def generate_ssh_keys():
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_VERSIONING_CLASS':
'rest_framework.versioning.URLPathVersioning',
'cvat.apps.engine.URLPathVersioning',
'ALLOWED_VERSIONS': ('v1', ),
'DEFAULT_PAGINATION_CLASS':
'rest_framework.pagination.PageNumberPagination',
Expand Down

0 comments on commit 55effe1

Please sign in to comment.