Example #1
0
    def __init__(self,
                 url_or_resource,
                 http_client=None,
                 extra_processors=None):
        if not http_client:
            http_client = SynchronousHttpClient()
        self.http_client = http_client

        processors = [WebsocketProcessor(), ClientProcessor()]
        if extra_processors is not None:
            processors.extend(extra_processors)
        loader = swaggerpy.Loader(http_client, processors)

        if isinstance(url_or_resource, basestring):
            log.debug("Loading from %s" % url_or_resource)
            self.api_docs = loader.load_resource_listing(url_or_resource)
        else:
            log.debug("Loading from %s" % url_or_resource.get('basePath'))
            self.api_docs = url_or_resource
            loader.process_resource_listing(self.api_docs)

        self.resources = {
            resource['name']: Resource(resource, http_client)
            for resource in self.api_docs['apis']
        }
Example #2
0
    def __init__(self, url_or_resource, http_client=None):
        if not http_client:
            http_client = SynchronousHttpClient()
        self.http_client = http_client

        loader = Loader(http_client, [WebsocketProcessor(), ClientProcessor()])

        if isinstance(url_or_resource, str):
            log.debug("Loading from %s" % url_or_resource)
            self.api_docs = loader.load_resource_listing(url_or_resource)
        else:
            log.debug("Loading from %s" % url_or_resource.get('basePath'))
            self.api_docs = url_or_resource
            loader.process_resource_listing(self.api_docs)

        self.resources = {
            resource['name']: Resource(resource, http_client)
            for resource in self.api_docs['apis']
        }
Example #3
0
    def __init__(self, url_or_resource, http_client=None,
                 api_base_path=None, raise_with=None):
        if not http_client:
            http_client = SynchronousHttpClient()
        # Wrap http client's errors with raise_with
        http_client.raise_with = raise_with
        self._http_client = http_client

        # Load Swagger APIs always synchronously
        loader = Loader(
            SynchronousHttpClient(headers=http_client._headers),
            [WebsocketProcessor(), ClientProcessor()])

        forced_api_base_path = api_base_path is not None
        # url_or_resource can be url of type str,
        # OR a dict of resource itself.
        if isinstance(url_or_resource, (str, unicode)):
            log.debug(u"Loading from %s" % url_or_resource)
            self._api_docs = loader.load_resource_listing(url_or_resource)
            parsed_uri = urlparse(url_or_resource)
            if not api_base_path:
                api_base_path = "{uri.scheme}://{uri.netloc}".format(
                    uri=parsed_uri)
        else:
            log.debug(u"Loading from %s" % url_or_resource.get(u'url'))
            self._api_docs = url_or_resource
            loader.process_resource_listing(self._api_docs)
            if not api_base_path:
                api_base_path = url_or_resource.get(u'url')

        self._resources = {}
        for resource in self._api_docs[u'apis']:
            if forced_api_base_path and 'api_declaration' in resource:
                resource['api_declaration']['basePath'] = api_base_path
            self._resources[resource[u'name']] = Resource(
                resource, http_client, api_base_path)
            setattr(self, resource['name'],
                    self._get_resource(resource[u'name']))