Skip to content

Commit

Permalink
Add swagger docs
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <[email protected]>
  • Loading branch information
KipSigei committed Jul 8, 2024
1 parent cb2c06e commit 9a9a7f0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion onadata/apps/api/viewsets/open_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def destroy(self, request, *args, **kwargs):
return Response(status=status.HTTP_204_NO_CONTENT)

@action(methods=["GET"], detail=True)
def schema(self, request, **kwargs):
def open_data_schema(self, request, **kwargs):
"""Tableau schema - headers and table alias."""
# pylint: disable=attribute-defined-outside-init
self.object = self.get_object()
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/api/viewsets/v2/tableau_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def get_tableau_table_schemas(self) -> List[dict]:
return ret

@action(methods=["GET"], detail=True)
def schema(self, request, **kwargs):
def open_data_schema(self, request, **kwargs):
# pylint: disable=attribute-defined-outside-init
self.object = self.get_object()
if isinstance(self.object.content_object, XForm):
Expand Down
10 changes: 9 additions & 1 deletion onadata/apps/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# enable the admin:
from django.contrib import admin
from django.contrib.staticfiles import views as staticfiles_views
from django.urls import include, re_path
from django.urls import include, re_path, path
from django.views.generic import RedirectView

from onadata.apps import sms_support
Expand All @@ -32,11 +32,19 @@
from onadata.apps.viewer import views as viewer_views
from onadata.libs.utils.analytics import init_analytics

from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView, SpectacularJSONAPIView

TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"

admin.autodiscover()

urlpatterns = [
path('schema/', SpectacularAPIView.as_view(), name='schema'),
path('schema/ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('schema/redoc/', SpectacularRedocView.as_view(), name='redoc'),
path('schema/json/', SpectacularJSONAPIView.as_view(), name='schema-json'),
path('schema/yaml/', SpectacularAPIView.as_view(), name='schema-yaml'),

# change Language
re_path(r"^i18n/", include(i18n)),
re_path("^api/v1/", include(api_v1_router.urls)),
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/messaging/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def to_representation(self, value):
"""
Get the model from ContentType object
"""
return value.model
return value


class MessageSerializer(serializers.ModelSerializer):
Expand Down
4 changes: 2 additions & 2 deletions onadata/libs/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class XFormListObjectPermissionFilter(AnonDjangoObjectPermissionFilter):
perm_format = "%(app_label)s.report_%(model_name)s"


class XFormListXFormPKFilter:
class XFormListXFormPKFilter(filters.BaseFilterBackend):
"""Filter forms via 'xform_pk' param."""

def filter_queryset(self, request, queryset, view):
Expand Down Expand Up @@ -761,7 +761,7 @@ def filter_queryset(self, request, queryset, view):


# pylint: disable=too-few-public-methods
class PublicDatasetsFilter:
class PublicDatasetsFilter(filters.BaseFilterBackend):
"""Public data set filter where the share attribute is True"""

# pylint: disable=unused-argument
Expand Down
5 changes: 3 additions & 2 deletions onadata/libs/mixins/anonymous_user_public_forms_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def _get_public_forms_queryset(self):

def get_queryset(self):
"""Public forms only for anonymous Users."""
if self.request and self.request.user.is_anonymous:
return self._get_public_forms_queryset()
if hasattr(self, 'request'):
if self.request and self.request.user.is_anonymous:
return self._get_public_forms_queryset()

return super().get_queryset()

0 comments on commit 9a9a7f0

Please sign in to comment.