4

I have been trying to integrate Swagger with Django Application and encounter this error: No operations defined in spec!

My project structure is

App 
    views.py 
    urls.py
    ..
App2 
    settings.py 
    urls.py
    ..

I am using drf_yasg for my purpose. I have included all details in settings.py and in App2 I have this in urls.py:

from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_view = get_schema_view(
   openapi.Info(
      title="Testing",
      default_version='v1',
      description="Doc Integration",
      terms_of_service="https://www.google.com/policies/terms/",
      contact=openapi.Contact(email="abc@abc.com"),
      license=openapi.License(name="BSD License"),
   ),
   public=True,
   permission_classes=(permissions.AllowAny,),
)

urlpatterns=[path("admin/", admin.site.urls),
            path("", include("app.urls")),
            path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
            path('redoc', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),]

My class views such as (class Att(generic.TemplateView) and methods are declared in views.py under App. I tried methods such as @swagger_auto_schema, @api_view, to display app class and functions in the documentation. But it just returns No operations defined in spec!.

I tried using routers to register the view as well but did not work, even django-rest-swagger fails. Any help is appreciated. Thanks!

Floura Angel
  • 99
  • 2
  • 6

1 Answers1

1

I have a project made of Django and I'm new to DRF. I had seen No operations defined in spec! as well while trying drf-yasg which is one of Swagger generators. Hope this way works for you. I imported ->

from rest_framework.views import APIView

The class in views.py was like

class FeedView(View):

and the functions showed up when I changed the class like

class FeedView(APIView):

I need to deal with @swagger_auto_schema, @api_view to make my API document works with proper parameters.

Phin
  • 68
  • 1
  • 7