def _get_components(self, registry): """ :param flask_rebar.rebar.HandlerRegistry registry: :return: """ components = {} schemas = get_unique_schema_definitions( registry=registry, base=self._ref_base, default_response_schema=self.default_response_schema, response_converter=self._response_converter, request_body_converter=self._request_body_converter, ) if schemas: components[sw.schemas] = schemas security_schemes = {} authenticators = get_unique_authenticators(registry) for authenticator in authenticators: # We should probably eventually check that scheme with the same name are identical # rather than just overwriting the existing scheme definition. security_schemes.update( self.authenticator_converter.get_security_schemes( authenticator)) if security_schemes: components[sw.security_schemes] = security_schemes return components
def _get_components(self, registry): """ :param flask_rebar.rebar.HandlerRegistry registry: :return: """ components = {} schemas = get_unique_schema_definitions( registry=registry, base=self._ref_base, default_response_schema=self.default_response_schema, response_converter=self._response_converter, request_body_converter=self._request_body_converter, ) if schemas: components[sw.schemas] = schemas security_schemes = self.authenticator_converter.get_security_schemes( registry) if security_schemes: components[sw.security_schemes] = security_schemes return components
def generate( self, registry, host=None, schemes=None, consumes=None, produces=None, sort_keys=True, ): """Generate a swagger specification from the provided `registry` `generate_swagger` implements the SwaggerGeneratorI interface. But for backwards compatibility, we are keeping the similarly named `generate` signature. :param flask_rebar.rebar.HandlerRegistry registry: :param str host: Overrides the initialized host :param Sequence[str] schemes: Overrides the initialized schemas :param Sequence[str] consumes: Overrides the initialized consumes :param Sequence[str] produces: Overrides the initialized produces :param bool sort_keys: Use OrderedDicts sorted by keys instead of dicts :rtype: dict """ default_authenticator = registry.default_authenticator security_definitions = self.authenticator_converter.get_security_schemes( registry ) definitions = get_unique_schema_definitions( registry=registry, base=self._ref_base, default_response_schema=self.default_response_schema, response_converter=self._response_converter, request_body_converter=self._request_body_converter, ) paths = self._get_paths( paths=registry.paths, default_headers_schema=registry.default_headers_schema ) if host and "://" in host: _, _, host = host.partition("://") swagger = { sw.swagger: self._get_version(), sw.info: self._get_info(), sw.host: host or self.host, sw.schemes: list(schemes or self.schemes), sw.consumes: list(consumes or self.consumes), sw.produces: list(produces or self.produces), sw.security_definitions: security_definitions, sw.paths: paths, sw.definitions: definitions, } if default_authenticator: swagger[ sw.security ] = self.authenticator_converter.get_security_requirement( default_authenticator ) if self.tags: swagger[sw.tags] = [tag.as_swagger() for tag in self.tags] if sort_keys: # Sort the swagger we generated by keys to produce a consistent output. swagger = recursively_convert_dict_to_ordered_dict(swagger) return swagger