Skip to content

Commit

Permalink
concepts/mappings | added query parameters for swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 25, 2020
1 parent fd7d75b commit 7837f25
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/common/params.py
@@ -0,0 +1,19 @@
from drf_yasg import openapi

q_param = openapi.Parameter('q', openapi.IN_QUERY, description="search text", type=openapi.TYPE_STRING)
page_param = openapi.Parameter('page', openapi.IN_QUERY, description="page number", type=openapi.TYPE_INTEGER)
exact_match_param = openapi.Parameter(
'exact_match', openapi.IN_QUERY, description="on | off (no wildcards)", type=openapi.TYPE_STRING, default='off'
)
limit_param = openapi.Parameter(
'limit', openapi.IN_QUERY, description="result list size", type=openapi.TYPE_INTEGER, default=25
)
sort_desc_param = openapi.Parameter(
'sortDesc', openapi.IN_QUERY, description="With q param (last_update, name, best_match)", type=openapi.TYPE_STRING,
)
sort_asc_param = openapi.Parameter(
'sortAsc', openapi.IN_QUERY, description="With q param (last_update, name, best_match)", type=openapi.TYPE_STRING,
)
verbose_param = openapi.Parameter(
'verbose', openapi.IN_QUERY, type=openapi.TYPE_BOOLEAN, default=False,
)
9 changes: 9 additions & 0 deletions core/concepts/views.py
@@ -1,5 +1,6 @@
from django.db.models import F
from django.shortcuts import get_object_or_404
from drf_yasg.utils import swagger_auto_schema
from pydash import get
from rest_framework import status
from rest_framework.generics import RetrieveAPIView, DestroyAPIView, ListCreateAPIView, RetrieveUpdateDestroyAPIView, \
Expand All @@ -11,6 +12,9 @@
HEAD, INCLUDE_INVERSE_MAPPINGS_PARAM, INCLUDE_RETIRED_PARAM
)
from core.common.mixins import ListWithHeadersMixin, ConceptDictionaryMixin
from core.common.params import (
q_param, limit_param, sort_desc_param, page_param, exact_match_param, sort_asc_param, verbose_param
)
from core.common.views import SourceChildCommonBaseView
from core.concepts.documents import ConceptDocument
from core.concepts.models import Concept, LocalizedText
Expand Down Expand Up @@ -65,6 +69,11 @@ def get_queryset(self):
'parent__organization', 'parent__user',
).prefetch_related('names', 'descriptions')

@swagger_auto_schema(
manual_parameters=[
q_param, limit_param, sort_desc_param, sort_asc_param, exact_match_param, page_param, verbose_param
]
)
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)

Expand Down
9 changes: 9 additions & 0 deletions core/mappings/views.py
@@ -1,12 +1,16 @@
from django.db.models import F
from django.shortcuts import get_object_or_404
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework.generics import DestroyAPIView, UpdateAPIView, RetrieveAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response

from core.common.constants import HEAD
from core.common.mixins import ListWithHeadersMixin, ConceptDictionaryMixin
from core.common.params import (
q_param, limit_param, sort_desc_param, page_param, exact_match_param, sort_asc_param, verbose_param
)
from core.common.views import SourceChildCommonBaseView
from core.concepts.permissions import CanEditParentDictionary, CanViewParentDictionary
from core.mappings.documents import MappingDocument
Expand Down Expand Up @@ -195,5 +199,10 @@ def get_queryset(self):
'parent__organization', 'parent__user',
)

@swagger_auto_schema(
manual_parameters=[
q_param, limit_param, sort_desc_param, sort_asc_param, exact_match_param, page_param, verbose_param
]
)
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)

0 comments on commit 7837f25

Please sign in to comment.