Skip to content
Prev Previous commit
Return nested schemas
  • Loading branch information
lovelydinosaur committed Sep 30, 2016
commit 0844cb5114a8a97a4f0f0711fabea37f6f5bf091
29 changes: 13 additions & 16 deletions rest_framework/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def get_filter_fields(self, path, method, view):
if not self.is_list_endpoint(path, method, view):
return []

if not hasattr(view, 'filter_backends'):
if not getattr(view, 'filter_backends', None):
return []

fields = []
Expand All @@ -368,9 +368,9 @@ def get_keys(self, path, method, view):
/users/ ("users", "list"), ("users", "create")
/users/{pk}/ ("users", "read"), ("users", "update"), ("users", "delete")
/users/enabled/ ("users", "enabled") # custom viewset list action
/users/{pk}/star/ ("users", "enabled") # custom viewset detail action
/users/{pk}/groups/ ("groups", "list"), ("groups", "create")
/users/{pk}/groups/{pk}/ ("groups", "read"), ("groups", "update"), ("groups", "delete")
/users/{pk}/star/ ("users", "star") # custom viewset detail action
/users/{pk}/groups/ ("users", "groups", "list"), ("users", "groups", "create")
/users/{pk}/groups/{pk}/ ("users", "groups", "read"), ("users", "groups", "update"), ("users", "groups", "delete")
"""
if hasattr(view, 'action'):
# Viewsets have explicitly named actions.
Expand All @@ -385,18 +385,15 @@ def get_keys(self, path, method, view):
else:
action = self.default_mapping[method.lower()]

named_path_components = [
component for component
in path.strip('/').split('/')
if '{' not in component
]

if is_custom_action(action):
# Custom action, eg "/users/{pk}/activate/", "/users/active/"
idx = -2
else:
# Default action, eg "/users/", "/users/{pk}/"
idx = -1
return named_path_components[:-1] + [action]

path_components = path.strip('/').split('/')
named_path_components = [
component for component in path_components if '{' not in component
]
try:
return (named_path_components[idx], action)
except IndexError:
return (action,)
# Default action, eg "/users/", "/users/{pk}/"
return named_path_components + [action]