Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swagger docs #2622

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading