Exemple #1
0
def test_flaskify_endpoint():
    assert flask_utils.flaskify_endpoint("module.function") == "module_function"
    assert flask_utils.flaskify_endpoint("function") == "function"

    name = 'module.function'
    randlen = 6
    res = flask_utils.flaskify_endpoint(name, randlen)
    assert res.startswith('module_function')
    assert len(res) == len(name) + 1 + randlen
Exemple #2
0
def test_flaskify_endpoint():
    assert flask_utils.flaskify_endpoint(
        "module.function") == "module_function"
    assert flask_utils.flaskify_endpoint("function") == "function"

    name = 'module.function'
    randlen = 6
    res = flask_utils.flaskify_endpoint(name, randlen)
    assert res.startswith('module_function')
    assert len(res) == len(name) + 1 + randlen
Exemple #3
0
    def console_ui_home(self):
        """
        Home page of the OpenAPI Console UI.

        :return:
        """
        openapi_json_route_name = "{blueprint}.{prefix}_openapi_json"
        escaped = flask_utils.flaskify_endpoint(self.base_path)
        openapi_json_route_name = openapi_json_route_name.format(
            blueprint=escaped,
            prefix=escaped
        )
        template_variables = {
            'openapi_spec_url': flask.url_for(openapi_json_route_name),
            **self.options.openapi_console_ui_index_template_variables,
        }
        if self.options.openapi_console_ui_config is not None:
            template_variables['configUrl'] = 'swagger-ui-config.json'

        # Use `render_template_string` instead of `render_template` to circumvent the flask
        # template lookup mechanism and explicitly render the template of the current blueprint.
        # https://github.com/zalando/connexion/issues/1289#issuecomment-884105076
        template_dir = pathlib.Path(self.options.openapi_console_ui_from_dir)
        index_path = template_dir / 'index.j2'
        return flask.render_template_string(index_path.read_text(), **template_variables)
Exemple #4
0
 def _set_blueprint(self):
     logger.debug('Creating API blueprint: %s', self.base_path)
     endpoint = flask_utils.flaskify_endpoint(self.base_path)
     self.blueprint = flask.Blueprint(
         endpoint,
         __name__,
         url_prefix=self.base_path,
         template_folder=str(self.options.openapi_console_ui_from_dir))
Exemple #5
0
 def _set_blueprint(self):
     logger.debug('Creating API blueprint: %s', self.base_url)
     endpoint = flask_utils.flaskify_endpoint(self.base_url)
     self.blueprint = flask.Blueprint(endpoint,
                                      __name__,
                                      url_prefix=self.base_url,
                                      template_folder=str(
                                          self.swagger_path))
Exemple #6
0
    def _add_operation_internal(self, method, path, operation):
        operation_id = operation.operation_id
        logger.debug('... Adding %s -> %s', method.upper(), operation_id,
                     extra=vars(operation))

        flask_path = flask_utils.flaskify_path(path, operation.get_path_parameter_types())
        endpoint_name = flask_utils.flaskify_endpoint(operation.operation_id,
                                                      operation.randomize_endpoint)
        function = operation.function
        self.blueprint.add_url_rule(flask_path, endpoint_name, function, methods=[method])
Exemple #7
0
    def _add_operation_internal(self, method, path, operation):
        operation_id = operation.operation_id
        logger.debug('... Adding %s -> %s', method.upper(), operation_id,
                     extra=vars(operation))

        flask_path = flask_utils.flaskify_path(path, operation.get_path_parameter_types())
        endpoint_name = flask_utils.flaskify_endpoint(operation.operation_id,
                                                      operation.randomize_endpoint)
        function = operation.function
        self.blueprint.add_url_rule(flask_path, endpoint_name, function, methods=[method])
Exemple #8
0
    def console_ui_home(self):
        """
        Home page of the OpenAPI Console UI.

        :return:
        """
        openapi_json_route_name = "{blueprint}.{prefix}_openapi_json"
        escaped = flask_utils.flaskify_endpoint(self.base_path)
        openapi_json_route_name = openapi_json_route_name.format(
            blueprint=escaped, prefix=escaped)
        template_variables = {
            'openapi_spec_url': flask.url_for(openapi_json_route_name)
        }
        if self.options.openapi_console_ui_config is not None:
            template_variables['configUrl'] = 'swagger-ui-config.json'
        return flask.render_template('index.j2', **template_variables)
Exemple #9
0
 def _set_blueprint(self):
     logger.debug('Creating API blueprint: %s', self.base_path)
     endpoint = flask_utils.flaskify_endpoint(self.base_path)
     self.blueprint = flask.Blueprint(endpoint, __name__, url_prefix=self.base_path,
                                      template_folder=str(self.options.openapi_console_ui_from_dir))