def test_flaskify_endpoint(): assert utils.flaskify_endpoint("module.function") == "module_function" assert utils.flaskify_endpoint("function") == "function" name = 'module.function' randlen = 6 res = utils.flaskify_endpoint(name, randlen) assert res.startswith('module_function') assert len(res) == len(name) + 1 + randlen
def __init__(self, method: str, path: str, operation: dict, app_produces: list, app_security: list, security_definitions: dict, definitions: dict): """ This class uses the OperationID identify the module and function that will handle the operation From Swagger Specification: **OperationID** A friendly name for the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operation id to uniquely identify an operation. :param method: HTTP method :param path: :param operation: swagger operation object """ self.method = method self.path = path self.security_definitions = security_definitions self.definitions = definitions self.operation = operation self.operation_id = operation['operationId'] # todo support definition references # todo support references to application level parameters self.parameters = operation.get('parameters', []) self.produces = operation.get('produces', app_produces) self.endpoint_name = flaskify_endpoint(self.operation_id) self.security = operation.get('security', app_security) self.__undecorated_function = get_function_from_name(self.operation_id)
def create_blueprint(self, base_url=None): """ :type base_url: str | None :rtype: flask.Blueprint """ base_url = base_url or self.base_url logger.debug('Creating API blueprint: %s', base_url) endpoint = utils.flaskify_endpoint(base_url) blueprint = flask.Blueprint(endpoint, __name__, url_prefix=base_url, template_folder=str(SWAGGER_UI_PATH)) return blueprint
def __init__(self, method, path, operation, app_produces, app_security, security_definitions, definitions): """ This class uses the OperationID identify the module and function that will handle the operation From Swagger Specification: **OperationID** A friendly name for the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operation id to uniquely identify an operation. :param method: HTTP method :type method: str :param path: :type path: str :param operation: swagger operation object :type operation: dict :param app_produces: list of content types the application can return by default :type app_produces: list :param app_security: list of security rules the application uses by default :type app_security: list :param security_definitions: `Security Definitions Object <https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#security-definitions-object>`_ :type security_definitions: dict :param definitions: `Definitions Object <https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#definitionsObject>`_ :type definitions: dict """ self.method = method self.path = path self.security_definitions = security_definitions self.definitions = definitions self.operation = operation self.operation_id = operation["operationId"] # todo support definition references # todo support references to application level parameters self.parameters = operation.get("parameters", []) self.produces = operation.get("produces", app_produces) self.endpoint_name = flaskify_endpoint(self.operation_id) self.security = operation.get("security", app_security) self.__undecorated_function = get_function_from_name(self.operation_id)
def test_flaskify_endpoint(): assert utils.flaskify_endpoint("module.function") == "module_function" assert utils.flaskify_endpoint("function") == "function"
def create_blueprint(self, base_url: str = None) -> flask.Blueprint: base_url = base_url or self.base_url logger.debug("Creating API blueprint: %s", base_url) endpoint = utils.flaskify_endpoint(base_url) blueprint = flask.Blueprint(endpoint, __name__, url_prefix=base_url, template_folder=str(SWAGGER_UI_PATH)) return blueprint