              else:
                  view.request = None
  
              link = self.get_link(path, method, callback, view)
              links.append((key, link))
  
          if not link:
              return None
  
          # Generate the schema content structure, from the endpoints.
 
</s> remove         if not link:
 </s> add         if not links: </s> remove         # Generate the schema content structure, from the endpoints.
        # ('users', 'list'), Link -> {'users': {'list': Link()}}
 </s> add         # Generate the schema content structure, eg:
        # {'users': {'list': Link()}} </s> remove         for key, link in links:
            insert_into(content, key, link)
 </s> add         for category, action, link in links:
            if category is None:
                content[action] = link
            elif category in content:
                content[category][action] = link
            else:
                content[category] = {action: link} </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         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
            links.append((category, action, link))
              else:
                  view.request = None
  
              link = self.get_link(path, method, callback, view)
            links.append((category, action, link))
  
          if not link:
              return None
  
          # Generate the schema content structure, from the endpoints.
keep keep keep keep replace keep keep keep keep keep
 Fix schema categories for custom list actions (#4386) 
rest_framework/schemas.py