Example #1
0
    def flattened_spec(self):
        """
        Representation of the current swagger specs that could be written to a single file.
        NOTE: The representation strips out all the definitions that are not referenced
        :return:
        """

        if self._flattened_spec is None:
            # self.resources is None if the specs are not built
            if self.resources is None or not self.config['validate_swagger_spec']:
                raise RuntimeError('Swagger Specs have to be built and validated before flattening.')

            if self.origin_url is None:
                warnings.warn(
                    message='It is recommended to set origin_url to your spec before flattering it. '
                            'Doing so internal paths will be hidden, reducing the amount of exposed information.',
                    category=Warning,
                )

            self._flattened_spec = strip_xscope(
                spec_dict=flattened_spec(
                    spec_dict=self.spec_dict,
                    spec_resolver=self.resolver,
                    spec_url=self.origin_url,
                    http_handlers=build_http_handlers(self.http_client),
                ),
            )

        return self._flattened_spec
Example #2
0
    def flattened_spec(self):
        """
        Representation of the current swagger specs that could be written to a single file.
        :rtype: dict
        """

        if not self.config['validate_swagger_spec']:
            log.warning(
                'Flattening unvalidated specs could produce invalid specs. '
                'Use it at your risk or enable `validate_swagger_specs`', )

        return strip_xscope(spec_dict=flattened_spec(swagger_spec=self), )
Example #3
0
    def _parse_spec_from_dict(self, spec_dict):
        """
        load_spec_dict will load the open api document into a dict. We use this
        function to parse the dict into a bravado Spec instance.

        :param spec_dict: The output of load_spec_dict
        :return: A Spec instance which holds all the dict information in an
                 accessible way.
        """
        config = {'use_models': False}
        url_string = self.http_response.get_url().url_string

        with warnings.catch_warnings(record=True) as w:
            try:
                spec_dict = flattened_spec(spec_dict, spec_url=url_string)
            except RefResolutionError, e:
                msg = ('The document at "%s" is not a valid Open API specification.'
                       ' The following exception was raised while trying to flatten'
                       ' the specification: "%s".')
                om.out.debug(msg % (self.http_response.get_url(), e))
                return None
Example #4
0
    def flattened_spec(self):
        """
        Representation of the current swagger specs that could be written to a single file.
        NOTE: The representation strips out all the definitions that are not referenced
        :return:
        """

        if not self.config['validate_swagger_spec']:
            raise RuntimeError(
                'Swagger Specs have to be validated before flattening.')

        # If resources are defined it means that Spec has been built and so swagger specs have been validated
        if self.resources is None:
            self._validate_spec()

        return strip_xscope(spec_dict=flattened_spec(
            spec_dict=self.spec_dict,
            spec_resolver=self.resolver,
            spec_url=self.origin_url,
            http_handlers=build_http_handlers(self.http_client),
            spec_definitions=self.definitions,
        ), )
Example #5
0
    def _parse_spec_from_dict(self, spec_dict):
        """
        load_spec_dict will load the open api document into a dict. We use this
        function to parse the dict into a bravado Spec instance.

        :param spec_dict: The output of load_spec_dict
        :return: A Spec instance which holds all the dict information in an
                 accessible way.
        """
        config = {'use_models': False}
        url_string = self.http_response.get_url().url_string

        with warnings.catch_warnings(record=True) as w:
            try:
                spec_dict = flattened_spec(spec_dict, spec_url=url_string)
            except RefResolutionError, e:
                msg = (
                    'The document at "%s" is not a valid Open API specification.'
                    ' The following exception was raised while trying to flatten'
                    ' the specification: "%s".')
                om.out.debug(msg % (self.http_response.get_url(), e))
                return None
Example #6
0
    def flattened_spec(self):
        """
        Representation of the current swagger specs that could be written to a single file.
        NOTE: The representation strips out all the definitions that are not referenced
        :return:
        """

        if not self.config['validate_swagger_spec']:
            raise RuntimeError('Swagger Specs have to be validated before flattening.')

        # If resources are defined it means that Spec has been built and so swagger specs have been validated
        if self.resources is None:
            self._validate_spec()

        return strip_xscope(
            spec_dict=flattened_spec(
                spec_dict=self.spec_dict,
                spec_resolver=self.resolver,
                spec_url=self.origin_url,
                http_handlers=build_http_handlers(self.http_client),
                spec_definitions=self.definitions,
            ),
        )