mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 13:54:47 +03:00
Return nested schemas
This commit is contained in:
parent
9ba36c23bb
commit
0844cb5114
|
@ -350,7 +350,7 @@ class SchemaGenerator(object):
|
||||||
if not self.is_list_endpoint(path, method, view):
|
if not self.is_list_endpoint(path, method, view):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if not hasattr(view, 'filter_backends'):
|
if not getattr(view, 'filter_backends', None):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
fields = []
|
fields = []
|
||||||
|
@ -368,9 +368,9 @@ class SchemaGenerator(object):
|
||||||
/users/ ("users", "list"), ("users", "create")
|
/users/ ("users", "list"), ("users", "create")
|
||||||
/users/{pk}/ ("users", "read"), ("users", "update"), ("users", "delete")
|
/users/{pk}/ ("users", "read"), ("users", "update"), ("users", "delete")
|
||||||
/users/enabled/ ("users", "enabled") # custom viewset list action
|
/users/enabled/ ("users", "enabled") # custom viewset list action
|
||||||
/users/{pk}/star/ ("users", "enabled") # custom viewset detail action
|
/users/{pk}/star/ ("users", "star") # custom viewset detail action
|
||||||
/users/{pk}/groups/ ("groups", "list"), ("groups", "create")
|
/users/{pk}/groups/ ("users", "groups", "list"), ("users", "groups", "create")
|
||||||
/users/{pk}/groups/{pk}/ ("groups", "read"), ("groups", "update"), ("groups", "delete")
|
/users/{pk}/groups/{pk}/ ("users", "groups", "read"), ("users", "groups", "update"), ("users", "groups", "delete")
|
||||||
"""
|
"""
|
||||||
if hasattr(view, 'action'):
|
if hasattr(view, 'action'):
|
||||||
# Viewsets have explicitly named actions.
|
# Viewsets have explicitly named actions.
|
||||||
|
@ -385,18 +385,15 @@ class SchemaGenerator(object):
|
||||||
else:
|
else:
|
||||||
action = self.default_mapping[method.lower()]
|
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):
|
if is_custom_action(action):
|
||||||
# Custom action, eg "/users/{pk}/activate/", "/users/active/"
|
# Custom action, eg "/users/{pk}/activate/", "/users/active/"
|
||||||
idx = -2
|
return named_path_components[:-1] + [action]
|
||||||
else:
|
|
||||||
# Default action, eg "/users/", "/users/{pk}/"
|
|
||||||
idx = -1
|
|
||||||
|
|
||||||
path_components = path.strip('/').split('/')
|
# Default action, eg "/users/", "/users/{pk}/"
|
||||||
named_path_components = [
|
return named_path_components + [action]
|
||||||
component for component in path_components if '{' not in component
|
|
||||||
]
|
|
||||||
try:
|
|
||||||
return (named_path_components[idx], action)
|
|
||||||
except IndexError:
|
|
||||||
return (action,)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user