Beispiel #1
0
    def endpoints(self) -> dict:
        """ 获得所有的端点

        return: {
            {path:method}: {callback}
        }
        """
        if not hasattr(self, '_path_method_conf'):
            self._path_method_conf = {}
            sg = SchemaGenerator()
            sg.get_schema()
            for path, method, callback in sg.endpoints:
                endpoint = path + ':' + method
                # 如果存在版本控制,遍历出所有的 version
                if '{version}' in path:
                    for allowed_versions in settings.REST_FRAMEWORK['ALLOWED_VERSIONS']:
                        version_endpoint = endpoint.replace('{version}', allowed_versions)
                        if version_endpoint not in self.path_unauthorized_conf:
                            version_path = path.replace('{version}', allowed_versions)
                            r = getattr(self.anonymous, method.lower())(version_path, )
                            if r.status_code == 404:
                                continue
                        self._path_method_conf[version_endpoint] = callback
                else:
                    self._path_method_conf[endpoint] = callback
        return self._path_method_conf
Beispiel #2
0
    def handle(self, *args, **options):
        assert coreapi is not None, 'coreapi must be installed.'

        generator = SchemaGenerator(url=options['url'],
                                    title=options['title'],
                                    description=options['description'])

        schema = generator.get_schema(request=None, public=True)

        renderer = self.get_renderer(options['format'])
        output = renderer.render(schema, renderer_context={})
        self.stdout.write(output.decode())
    def handle(self, *args, **options):
        assert coreapi is not None, 'coreapi must be installed.'

        generator = SchemaGenerator(
            url=options['url'],
            title=options['title'],
            description=options['description']
        )

        schema = generator.get_schema(request=None, public=True)

        renderer = self.get_renderer(options['format'])
        output = renderer.render(schema, renderer_context={})
        self.stdout.write(output.decode('utf-8'))