unknown
unknown

Reputation: 321

Why don't work drf-yasg openapi documentation?

Why don't work drf-yasg documentation. I see default settings only.

api_patterns = [
    url(r'^api/v1/users/', include('apps.users.urls')),
]

schema_view = get_schema_view(
    openapi.Info("PlasticJam", 'v1'),
    patterns=api_patterns,
    public=True,
)

urlpatterns += [
    url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]

views

@method_decorator(swagger_auto_schema(
    manual_parameters=[openapi.Parameter(
        name='users_count', in_=openapi.IN_QUERY, type='int', description='Count of users'
    )], 
    responses={'200': 'ok'}), name='list'
)
class UserListApiView(ListAPIView):
    """
    list:
    Users detail statistic

    Get dates range for statistic
    """
    queryset = User.objects.all()
    serializer_class = UserListSerializer

Upvotes: 0

Views: 2887

Answers (1)

Sedigheh Monavari
Sedigheh Monavari

Reputation: 407

in UserListApiView class, you should override get and put the decorator at the top of it.

@method_decorator(swagger_auto_schema(manual_parameters=[openapi.Parameter( name='users_count', in_=openapi.IN_QUERY, type='int', description='Count of users')],responses={'200': 'ok'}), name='list')

def get(self, request, *args, **kwargs):
    return super().get(request, *args, **kwargs)

Upvotes: 3

Related Questions