Skip to content

Commit

Permalink
added swagger to generate api tryout documenation
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 21, 2020
1 parent 489c5ec commit 93cb3de
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 3 deletions.
25 changes: 25 additions & 0 deletions core/collections/migrations/0008_auto_20200821_1342.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.0.9 on 2020-08-21 13:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('concepts', '0004_auto_20200722_0846'),
('mappings', '0005_auto_20200722_0846'),
('collections', '0007_auto_20200729_0718'),
]

operations = [
migrations.AlterField(
model_name='collection',
name='concepts',
field=models.ManyToManyField(blank=True, related_name='collections', to='concepts.Concept'),
),
migrations.AlterField(
model_name='collection',
name='mappings',
field=models.ManyToManyField(blank=True, related_name='collections', to='mappings.Mapping'),
),
]
4 changes: 2 additions & 2 deletions core/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Meta:
preferred_source = models.TextField(blank=True)
repository_type = models.TextField(default=DEFAULT_REPOSITORY_TYPE, blank=True)
custom_resources_linked_source = models.TextField(blank=True)
concepts = models.ManyToManyField('concepts.Concept', blank=True)
mappings = models.ManyToManyField('mappings.Mapping', blank=True)
concepts = models.ManyToManyField('concepts.Concept', blank=True, related_name='collections')
mappings = models.ManyToManyField('mappings.Mapping', blank=True, related_name='collections')
references = models.ManyToManyField('collections.CollectionReference', blank=True, related_name='collections')

@classmethod
Expand Down
6 changes: 6 additions & 0 deletions core/collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,15 @@ def get_object(self, queryset=None):


class CollectionExtrasView(CollectionExtrasBaseView, ListAPIView):
serializer_class = CollectionDetailSerializer

def list(self, request, *args, **kwargs):
return Response(get(self.get_object(), 'extras', {}))


class CollectionExtraRetrieveUpdateDestroyView(CollectionExtrasBaseView, RetrieveUpdateDestroyAPIView):
serializer_class = CollectionDetailSerializer

def retrieve(self, request, *args, **kwargs):
key = kwargs.get('extra')
instance = self.get_object()
Expand Down Expand Up @@ -526,6 +530,7 @@ def delete(self, request, *args, **kwargs):

class CollectionVersionProcessingView(CollectionBaseView):
permission_classes = (CanViewConceptDictionary,)
serializer_class = CollectionVersionDetailSerializer

def get_object(self, queryset=None):
return self.get_queryset().first()
Expand All @@ -552,6 +557,7 @@ def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
class CollectionVersionExportView(CollectionBaseView, ConceptContainerExportMixin):
entity = 'Collection'
permission_classes = (CanViewConceptDictionary,)
serializer_class = CollectionVersionDetailSerializer

def get_object(self, queryset=None):
return self.get_queryset().first()
Expand Down
3 changes: 3 additions & 0 deletions core/concepts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,15 @@ def get_object(self, queryset=None):

class ConceptExtrasView(ConceptExtrasBaseView, ListAPIView):
permission_classes = (CanViewParentDictionary,)
serializer_class = ConceptDetailSerializer

def list(self, request, *args, **kwargs):
return Response(get(self.get_object(), 'extras', {}))


class ConceptExtraRetrieveUpdateDestroyView(ConceptExtrasBaseView, RetrieveUpdateDestroyAPIView):
serializer_class = ConceptDetailSerializer

def get_permissions(self):
if self.request.method in ['GET', 'HEAD']:
return [CanViewParentDictionary()]
Expand Down
15 changes: 15 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'drf_yasg',
'django_elasticsearch_dsl',
'corsheaders',
'core.common.apps.CommonConfig',
Expand All @@ -64,6 +65,20 @@
'COERCE_DECIMAL_TO_STRING': False,
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}

SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'Basic': {
'type': 'basic'
},
'Token': {
'type': 'apiKey',
'name': 'Authorization',
'in': 'header'
}
}
}

MIDDLEWARE = [
Expand Down
6 changes: 6 additions & 0 deletions core/sources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,15 @@ def get_object(self, queryset=None):


class SourceExtrasView(SourceExtrasBaseView, ListAPIView):
serializer_class = SourceDetailSerializer

def list(self, request, *args, **kwargs):
return Response(get(self.get_object(), 'extras', {}))


class SourceExtraRetrieveUpdateDestroyView(SourceExtrasBaseView, RetrieveUpdateDestroyAPIView):
serializer_class = SourceDetailSerializer

def retrieve(self, request, *args, **kwargs):
key = kwargs.get('extra')
instance = self.get_object()
Expand Down Expand Up @@ -311,6 +315,7 @@ def delete(self, request, *args, **kwargs):

class SourceVersionProcessingView(SourceBaseView):
permission_classes = (CanViewConceptDictionary,)
serializer_class = SourceVersionDetailSerializer

def get_object(self, queryset=None):
return self.get_queryset().first()
Expand All @@ -337,6 +342,7 @@ def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
class SourceVersionExportView(SourceBaseView, ConceptContainerExportMixin):
entity = 'Source'
permission_classes = (CanViewConceptDictionary,)
serializer_class = SourceVersionDetailSerializer

def get_object(self, queryset=None):
return self.get_queryset().first()
Expand Down
17 changes: 17 additions & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,29 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

import core.concepts.views as concept_views
import core.mappings.views as mapping_views

SchemaView = get_schema_view(
openapi.Info(
title="OCL API",
default_version='v2',
description="OCL API v2",
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
url(r'^swagger(?P<format>\.json|\.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('admin/', admin.site.urls),
path('users/', include('core.users.urls')),
path('orgs/', include('core.orgs.urls')),
Expand Down
19 changes: 19 additions & 0 deletions core/users/migrations/0002_auto_20200821_1342.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.0.9 on 2020-08-21 13:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('orgs', '0002_auto_20200720_1450'),
('users', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='userprofile',
name='organizations',
field=models.ManyToManyField(related_name='users', to='orgs.Organization'),
),
]
2 changes: 1 addition & 1 deletion core/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
swappable = 'AUTH_USER_MODEL'

OBJECT_TYPE = USER_OBJECT_TYPE
organizations = models.ManyToManyField('orgs.Organization')
organizations = models.ManyToManyField('orgs.Organization', related_name='users')
company = models.TextField(null=True, blank=True)
location = models.TextField(null=True, blank=True)
preferred_locale = models.TextField(null=True, blank=True)
Expand Down
1 change: 1 addition & 0 deletions core/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def delete(self, request, *args, **kwargs):
class UserReactivateView(UserBaseView, UpdateAPIView):
permission_classes = (IsAdminUser, )
queryset = UserProfile.objects.filter(is_active=False)
serializer_class = UserDetailSerializer

def update(self, request, *args, **kwargs):
profile = self.get_object()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ redis==3.5.3
celery[redis]==3.1.17
kombu==4.6.10
django-elasticsearch-dsl==7.1.4
drf-yasg
git+https://github.com/snyaggarwal/django-queryset-csv

0 comments on commit 93cb3de

Please sign in to comment.