当前位置: 首页>>代码示例>>Python>>正文


Python connexion.App方法代码示例

本文整理汇总了Python中connexion.App方法的典型用法代码示例。如果您正苦于以下问题:Python connexion.App方法的具体用法?Python connexion.App怎么用?Python connexion.App使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connexion的用法示例。


在下文中一共展示了connexion.App方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_app

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def create_app():
    """ Creates the application for webapp utils. """
    utils_app = connexion.App("webapp-utils", options={'swagger_ui': True,
                                                       'openapi_spec_path': '/openapi.json'})
    utils_app.add_api(SPEC,
                      resolver=RestyResolver('app'),
                      validate_responses=True,
                      strict_validation=True,
                      base_path='/api')

    @utils_app.app.after_request
    def set_default_headers(response): # pylint: disable=unused-variable
        response.headers["Access-Control-Allow-Origin"] = "*"
        response.headers["Access-Control-Allow-Headers"] = "Content-Type, Access-Control-Allow-Headers, \
            Authorization, X-Requested-With, x-rh-identity"
        response.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS, PATCH, POST"

        return response

    return utils_app 
开发者ID:RedHatInsights,项目名称:vmaas,代码行数:22,代码来源:app.py

示例2: run_app

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def run_app(name, spec_file, port, debug_mode=True, run_in_background=False):
    import connexion
    specification_dir = os.path.join(root_url, "service")
    sys.path.insert(0, specification_dir)

    # Create the application instance
    app = connexion.App(__name__, specification_dir=specification_dir)

    # Read the open api .yml file to configure the endpoints
    # TODO allow for specifying multiple swagger files
    app.add_api(os.path.join(root_url, "openapi", spec_file))

    app.run(host='0.0.0.0', port=port, debug=debug_mode)

    port = int(os.environ.get("BURDOCK_SERVICE_PORT", port))
    return app 
开发者ID:opendifferentialprivacy,项目名称:whitenoise-system,代码行数:18,代码来源:service_utils.py

示例3: construct_test_server

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def construct_test_server():
    # Setup the API Server
    app = connexion.App(__name__, specification_dir='./../../src/rbb_swagger_server/swagger/')
    app.app.json_encoder = JSONEncoder
    app.add_api('swagger.yaml', arguments={'title': 'API to access the Rosbag Bazaar service'})

    # Setup link to the database and create new schema with fake data
    rbb_server_test.database.setup_database_for_test()

    # Enable debug
    app.app.config.from_object(TestConfig)

    @app.app.teardown_appcontext
    def shutdown_session(exception=None):
        Database.get_session().remove()

    # Allow requests from everywhere
    CORS(app.app)

    return app 
开发者ID:AMZ-Driverless,项目名称:rbb_core,代码行数:22,代码来源:test_server.py

示例4: configure_app

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def configure_app():
    # The model name has to match what is in
    # tools/prepare_swagger.sh controller.
    app = connexion.App(
        "ga4gh.drs.server",
        swagger_ui=True,
        swagger_json=True)
    app.add_api(SWAGGER_PATH)

    CORS(app.app)
    return app 
开发者ID:ga4gh,项目名称:data-repository-service-schemas,代码行数:13,代码来源:server.py

示例5: init_api_connexion

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def init_api_connexion(app: Flask) -> None:
    """Initialize Stable API"""
    spec_dir = path.join(ROOT_APP_DIR, 'api_connexion', 'openapi')
    connexion_app = connexion.App(__name__, specification_dir=spec_dir, skip_error_handlers=True)
    connexion_app.app = app
    api_bp = connexion_app.add_api(
        specification='v1.yaml', base_path='/api/v1', validate_responses=True, strict_validation=True
    ).blueprint
    app.register_error_handler(ProblemException, connexion_app.common_error_handler)
    app.extensions['csrf'].exempt(api_bp) 
开发者ID:apache,项目名称:airflow,代码行数:12,代码来源:init_views.py

示例6: setup_webapp

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def setup_webapp(config: configuration.Configuration):  # pragma: no cover

    arguments = {'deployer_scope': config.deployer_scope,
                 'token_url': config.token_url}
    logger.debug('Webapp Parameters', extra=arguments)
    app = connexion.App(__name__,
                        specification_dir='swagger/',
                        arguments=arguments,
                        auth_all_paths=True)
    app.add_api('lizzy.yaml')

    flask_app = app.app
    flask_app.json_encoder = JSONEncoder

    flask_app.register_error_handler(werkzeug.exceptions.NotFound,
                                     not_found_path_handler)

    flask_app.add_url_rule('/.well-known/schema-discovery',
                           'schema_discovery_endpoint',
                           expose_api_schema)

    flask_app.add_url_rule('/health',
                           'health_check_endpoint',
                           health_check)

    return app 
开发者ID:zalando-stups,项目名称:lizzy,代码行数:28,代码来源:service.py

示例7: main

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def main(options):
    try:
        app = connexion.App(__name__, specification_dir='rest_api/')
        app.add_api('video-analytics-serving.yaml',
                    arguments={'title': 'Video Analytics Serving API'})
        logger.info("Starting Tornado Server on port: %s", options.port)
        app.run(server='tornado', port=options.port)
    except Exception as error:
        logger.error("Error Starting Tornado Server") 
开发者ID:intel,项目名称:video-analytics-serving,代码行数:11,代码来源:__main__.py

示例8: run_wes_server

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def run_wes_server(args):
    app = connexion.App(__name__)
    backend = CWLAirflowBackend()
    def rs(x):
        return getattr(backend, x.split('.')[-1])
    app.add_api('openapi/swagger_configuration.yaml', resolver=Resolver(rs))
    app.run(port=args.port, host=args.host) 
开发者ID:Barski-lab,项目名称:cwl-airflow,代码行数:9,代码来源:server.py

示例9: __init__

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def __init__(self, *args, **kwargs):
        """Create a FleeceApp.

        Parameters are identical to a `connexion.App, with the exception of the
        below keyword argument.

        :param logging.Logger logger:
            A Logger instance returned by `fleece.log.get_logger()` to be used
            for capturing details about errors.

            If `logger` is None, a default logger object will be created.
        """
        logger = kwargs.pop("logger", None)
        if logger is None:
            self.logger = fleece.log.get_logger(__name__)
        else:
            self.logger = logger

        super(FleeceApp, self).__init__(*args, **kwargs)

        # Capture and log any unexpected exceptions raise by handler code:
        def error_handler(exception):
            self.logger.exception(exception)
            # A `None` return value will not modify the response.
            # It's possible to return new types of responses from an error
            # handler.
            # To do so, simply return a new `werkzeug.wrappers.Response`
            # object.

        self.add_error_handler(Exception, error_handler) 
开发者ID:rackerlabs,项目名称:fleece,代码行数:32,代码来源:connexion.py

示例10: build_flask_app

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def build_flask_app(project_name, app_name, openapi):
    """
    Create a new Flask backend application
    app_name is the Python application name, used as Flask import_name
    project_name is a "nice" name, used to identify the application
    """
    assert os.path.exists(openapi), "Missing openapi file {}".format(openapi)
    logger.debug("Initializing", app=app_name, openapi=openapi)

    # Start OpenAPI app
    app = connexion.App(import_name=app_name)
    app.name = project_name
    app.add_api(openapi)

    # Enable security
    security = flask_talisman.Talisman()
    security.init_app(app.app, **TALISMAN_CONFIG)

    # Enable wildcard CORS
    cors = flask_cors.CORS()
    cors.init_app(app.app, origins=["*"])

    # Add exception Json renderer
    for code, exception in werkzeug.exceptions.default_exceptions.items():
        app.app.register_error_handler(exception, handle_default_exceptions)

    # Redirect root to API
    app.add_url_rule(
        "/", "root", lambda: flask.redirect(app.options.openapi_console_ui_path)
    )

    # Dockerflow checks
    app.add_url_rule("/__heartbeat__", view_func=heartbeat_response)
    app.add_url_rule("/__lbheartbeat__", view_func=lbheartbeat_response)
    app.add_url_rule("/__version__", view_func=get_version)

    logger.debug("Initialized", app=app.name)
    return app 
开发者ID:mozilla,项目名称:code-coverage,代码行数:40,代码来源:build.py

示例11: main

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def main():
    app = connexion.App(__name__, specification_dir='./swagger/')
    app.app.json_encoder = encoder.JSONEncoder
    app.add_api('swagger.yaml', arguments={'title': 'Rosbag Bazaar API'})
    app.run(port=8080) 
开发者ID:AMZ-Driverless,项目名称:rbb_core,代码行数:7,代码来源:__main__.py

示例12: create_app

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def create_app(self):
        logging.getLogger('connexion.operation').setLevel('ERROR')
        app = connexion.App(__name__, specification_dir='../swagger/')
        app.app.json_encoder = JSONEncoder
        app.add_api('swagger.yaml')
        return app.app 
开发者ID:AMZ-Driverless,项目名称:rbb_core,代码行数:8,代码来源:__init__.py

示例13: run

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def run(self):
        self.conn = connexion.App(
            'tests',
            debug=True,
            specification_dir=os.path.dirname(__file__)
        )
        self.conn.add_api('swagger.yaml')
        self.conn.app.run(port=8080) 
开发者ID:Trax-air,项目名称:swagger-tester,代码行数:10,代码来源:test_swagger-tester.py

示例14: main

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def main():
    app = connexion.App(__name__, specification_dir='./swagger/')
    app.app.json_encoder = encoder.JSONEncoder
    app.add_api('swagger.yaml', arguments={'title': 'APIs for CentOS Community Container Pipeline Service'})
    app.run(port=8080) 
开发者ID:CentOS,项目名称:container-pipeline-service,代码行数:7,代码来源:__main__.py

示例15: init_app

# 需要导入模块: import connexion [as 别名]
# 或者: from connexion import App [as 别名]
def init_app(self, config, path):
        """
        Initialize Connexion App. See more info in [Connexion Github](https://github.com/zalando/connexion)
        :param config: The Flask configuration defined in the config.yaml:
        ```yaml
        pyms:
          services:
            requests: true
            swagger:
              path: ""
              file: "swagger.yaml"
          config: <!--
            DEBUG: true
            TESTING: false
            APP_NAME: "Python Microservice"
            APPLICATION_ROOT: ""
        ```
        :param path: The current path where is instantiated Microservice class:
        ```
        Microservice(path=__file__)
                     ^^^^--- This param
        ```
        :return: Flask
        """
        check_package_exists("connexion")
        specification_dir = self.path
        application_root = self._get_application_root(config)
        if not os.path.isabs(self.path):
            specification_dir = os.path.join(path, self.path)

        app = connexion.App(__name__,
                            specification_dir=specification_dir,
                            resolver=RestyResolver(self.project_dir))

        params = {
            "specification": get_bundled_specs(
                Path(os.path.join(specification_dir, self.file))) if prance else self.file,
            "arguments": {'title': config.APP_NAME},
            "base_path": application_root,
            "options": {"swagger_url": self.url},
        }

        # Fix Connexion issue https://github.com/zalando/connexion/issues/1135
        if application_root == "/":
            del params["base_path"]

        app.add_api(**params)
        # Invert the objects, instead connexion with a Flask object, a Flask object with
        application = app.app
        application.connexion_app = app
        return application 
开发者ID:python-microservices,项目名称:pyms,代码行数:53,代码来源:swagger.py


注:本文中的connexion.App方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。