Пример #1
0
    def get_links(self, request=None):
        # from rest_framework.schemas.generators import LinkNode,
        links = LinkNode()

        paths = []
        view_endpoints = []
        for path, method, callback in self.endpoints:
            view = self.create_view(callback, method, request)
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        prefix = self.determine_path_prefix(paths)

        for path, method, view in view_endpoints:
            if not self.has_view_permissions(path, method, view):
                continue
            link = view.schema.get_link(path, method, base_url=self.url)
            # 添加下面这一行方便在views编写过程中自定义参数.
            link._fields += self.get_core_fields(view)

            subpath = path[len(prefix):]
            keys = self.get_keys(subpath, method, view)

            # from rest_framework.schemas.generators import LinkNode, insert_into
            insert_into(links, keys, link)

        return links
Пример #2
0
    def get_links(self, request=None):
        links = LinkNode()

        paths = []
        view_endpoints = []
        for path, method, callback in self.endpoints:
            view = self.create_view(callback, method, request)
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        prefix = self.determine_path_prefix(paths)

        child_path = self.url.split('com')[1][:-1]
        for path, method, view in view_endpoints:
            if not self.has_view_permissions(path, method, view):
                link = self.get_link(path, method, view, base_url='')
            else:
                link = view.schema.get_link(path, method, base_url='')
            link._url = child_path + link._url
            link._encoding = "multipart/form-data"

            # 添加下面这一行方便在views编写过程中自定义参数.
            link._fields += self.get_core_fields(view, method)
            subpath = path[len(prefix):]
            keys = self.get_keys(subpath, method, view)
            # from rest_framework.schemas.generators import LinkNode, insert_into
            insert_into(links, keys, link)
        return links
Пример #3
0
    def get_links(self, request=None):
        """
        Return a dictionary containing all the links that should be
        included in the API schema.
        """
        links = LinkNode()

        # Generate (path, method, view) given (path, method, callback).
        paths = []
        view_endpoints = []
        for path, method, callback in self.endpoints:
            view = self.create_view(callback, method, request)
            if getattr(view, 'exclude_from_schema', False):
                continue
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        prefix = self.determine_path_prefix(paths)

        for path, method, view in view_endpoints:
            if not self.has_view_permissions(path, method, view):
                continue
            link = self.get_link(path, method, view, version=getattr(request, 'version', None))
            subpath = path[len(prefix):]
            keys = self.get_keys(subpath, method, view)
            try:
                insert_into(links, keys, link)
            except Exception:
                continue
        return links
Пример #4
0
    def get_links(self, request=None):
        """
        Return a dictionary containing all the links that should be
        included in the API schema.
        """
        links = LinkNode()

        # Generate (path, method, view) given (path, method, callback).
        paths = []
        view_endpoints = []
        for path, method, callback in self.endpoints:
            view = self.create_view(callback, method, request)
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        prefix = self.determine_path_prefix(paths)

        for path, method, view in view_endpoints:
            if path.startswith('/schema'):
                continue
            # TODO(Roar): Find a good way to determine if an endpoint should be
            # hidden from the documentation
            # if not self.has_view_permissions(path, method, view):
            #     continue
            link = self.get_link(path, method, view)
            subpath = path[len(prefix):]
            keys = self.get_keys(subpath, method, view)
            insert_into(links, keys, link)

        return links
Пример #5
0
    def get_links(self, request=None):
        """
        Return a dictionary containing all the links that should be
        included in the API schema.
        """
        links = LinkNode()

        # Generate (path, method, view) given (path, method, callback).
        paths = []
        view_endpoints = []
        for path_with_kwargs, method, callback in self.endpoints:
            path, kwargs = path_with_kwargs
            view = self.create_view(callback, method, request)
            view.kwargs = kwargs
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        prefix = self.determine_path_prefix(paths)

        for path, method, view in view_endpoints:
            if not self.has_view_permissions(path, method, view):
                continue
            link = view.schema.get_link(path, method, base_url=self.url)
            subpath = path[len(prefix):]
            keys = self.get_keys(subpath, method, view)
            insert_into(links, keys, link)

        return links
Пример #6
0
    def get_links(self, request=None):
        links = LinkNode()
        # Generate (path, method, view) given (path, method, callback).
        paths = []
        view_endpoints = []
        for path, method, callback in self.endpoints:
            view = self.create_view(callback, method, request)
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        prefix = self.determine_path_prefix(paths)

        for path, method, view in view_endpoints:
            if not self.has_view_permissions(path, method, view):
                continue
            fields = view.schema.get_path_fields(path, method)
            fields += view.schema.get_serializer_fields(path, method)
            fields += view.schema.get_pagination_fields(path, method)
            fields += view.schema.get_filter_fields(path, method)

            manual_fields = view.schema.get_manual_fields(path, method)
            fields = view.schema.update_fields(fields, manual_fields)

            if fields and any(
                [field.location in ('form', 'body') for field in fields]):
                encoding = view.schema.get_encoding(path, method)
            else:
                encoding = None

            description = view.schema.get_description(path, method)
            if description and len(description) > 0:
                query_fields, description = self.get_docstring_fields(
                    description)
                fields += query_fields
            if self.url and path.startswith('/'):
                path = path[1:]

            link = coreapi.Link(url=urlparse.urljoin(self.url, path),
                                action=method.lower(),
                                encoding=encoding,
                                fields=fields,
                                description=description)

            subpath = path[len(prefix):]
            keys = self.get_keys(subpath, method, view)
            insert_into(links, keys, link)

        return links
    def get_links(self, request=None):
        """Almost copy of parent, here I use subpath to create the link and save the base path
        Also I call the new get definitions, which generate object definitions from serializers ued in views"""
        links = LinkNode()

        # Generate (path, method, view) given (path, method, callback).
        paths = []
        view_endpoints = []
        for path, method, callback in self.endpoints:
            view = self.create_view(callback, method, request)
            if getattr(view, 'exclude_from_schema', False):
                continue
            path = self.coerce_path(path, method, view)
            paths.append(path)
            view_endpoints.append((path, method, view))

        # Only generate the path prefix for paths that will be included
        if not paths:
            return None
        self.prefix = self.determine_path_prefix(paths)

        for path, method, view in view_endpoints:
            if self.check_view_permissions and not self.has_view_permissions(
                    path, method, view):
                continue
            prefix_len = len(self.prefix)
            if prefix_len == 1:  # meaning prefix == '/', in other words there is not a common prefix
                subpath = path
            else:
                subpath = path[prefix_len:]
            link = view.schema.get_link(subpath, method, base_url=self.url)
            keys = self.get_keys(subpath, method, view)
            insert_into(links, keys, link)
            obj_def = self.add_object_definitions(method, view)
            if obj_def:
                if obj_def.title not in self.definitions:
                    self.definitions[obj_def.title] = obj_def
        return links