                  path = self.get_path(path_regex)
                  callback = pattern.callback
                  if self.should_include_endpoint(path, callback):
                      for method in self.get_allowed_methods(callback):
                          key = self.get_key(path, method, callback)
                          endpoint = (key, path, method, callback)
                          api_endpoints.append(endpoint)
  
              elif isinstance(pattern, RegexURLResolver):
                  nested_endpoints = self.get_api_endpoints(
                      patterns=pattern.url_patterns,
 
</s> remove         return api_endpoints
 </s> add         return self.add_categories(api_endpoints)

    def add_categories(self, api_endpoints):
        """
        (path, method, action, callback) -> (path, method, category, action, callback)
        """
        # Determine the top level categories for the schema content,
        # based on the URLs of the endpoints. Eg `set(['users', 'organisations'])`
        paths = [endpoint[0] for endpoint in api_endpoints]
        categories = self.get_categories(paths)

        return [
            (path, method, self.get_category(categories, path), action, callback)
            for (path, method, action, callback) in api_endpoints
        ] </s> remove         for key, path, method, callback in self.endpoints:
 </s> add         for path, method, category, action, callback in self.endpoints: </s> remove     def get_key(self, path, method, callback):
 </s> add     def get_action(self, path, method, callback): </s> remove         action = actions[method.lower()]

        if category:
            return (category, action)
        return (action,)
 </s> add         return actions[method.lower()]

    def get_categories(self, paths):
        categories = set()
        split_paths = set([
            tuple(path.split("{")[0].strip('/').split('/'))
            for path in paths
        ])

        while split_paths:
            for split_path in list(split_paths):
                if len(split_path) == 0:
                    split_paths.remove(split_path)
                elif len(split_path) == 1:
                    categories.add(split_path[0])
                    split_paths.remove(split_path)
                elif split_path[0] in categories:
                    split_paths.remove(split_path)

        return categories

    def get_category(self, categories, path):
        path_components = path.split("{")[0].strip('/').split('/')
        for path_component in path_components:
            if path_component in categories:
                return path_component
        return None </s> remove def insert_into(target, keys, item):
    """
    Insert `item` into the nested dictionary `target`.

    For example:

        target = {}
        insert_into(target, ('users', 'list'), Link(...))
        insert_into(target, ('users', 'detail'), Link(...))
        assert target == {'users': {'list': Link(...), 'detail': Link(...)}}
    """
    for key in keys[:1]:
        if key not in target:
            target[key] = {}
        target = target[key]
    target[keys[-1]] = item


 </s> add 
                        action = self.get_action(path, method, callback)
                        endpoint = (path, method, action, callback)
                  path = self.get_path(path_regex)
                  callback = pattern.callback
                  if self.should_include_endpoint(path, callback):
                      for method in self.get_allowed_methods(callback):
                        action = self.get_action(path, method, callback)
                        endpoint = (path, method, action, callback)
                        action = self.get_action(path, method, callback)
                        endpoint = (path, method, action, callback)
                          api_endpoints.append(endpoint)
  
              elif isinstance(pattern, RegexURLResolver):
                  nested_endpoints = self.get_api_endpoints(
                      patterns=pattern.url_patterns,
keep keep keep keep replace replace keep keep keep keep keep
 Fix schema categories for custom list actions (#4386) 
rest_framework/schemas.py