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

feat: add is_list option to view action method #331

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/drf_yasg/inspectors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def should_page(self):
return False

if self.method.lower() != 'get':
return False
return self.overrides.get('should_page', False)

return is_list_view(self.path, self.method, self.view)

Expand Down
7 changes: 5 additions & 2 deletions src/drf_yasg/inspectors/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ def get_default_responses(self):
default_schema = self.serializer_to_schema(default_schema) or ''

if default_schema:
if is_list_view(self.path, self.method, self.view) and self.method.lower() == 'get':
is_list = self.overrides.get('is_list', False)
should_page = self.overrides.get('should_page', False)
if (is_list or should_page) or\
(is_list_view(self.path, self.method, self.view) and self.method.lower() == 'get'):
default_schema = openapi.Schema(type=openapi.TYPE_ARRAY, items=default_schema)
if self.should_page():
if should_page or self.should_page():
default_schema = self.get_paginated_response(default_schema) or default_schema

return OrderedDict({str(default_status): default_schema})
Expand Down
3 changes: 3 additions & 0 deletions src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ def is_list_view(path, method, view):
# for ViewSets, it could be the default 'list' action, or a list_route
action = getattr(view, 'action', '')
method = getattr(view, action, None) or method
is_list = getattr(method, 'is_list', False)
if is_list:
return True
detail = getattr(method, 'detail', None)
suffix = getattr(view, 'suffix', None)
if action in ('list', 'create') or detail is False or suffix == 'List':
Expand Down