def main(): config = get_config() app = web.Application() aiohttp_jinja2.setup( app, loader=jinja2.FileSystemLoader("src/templates") ) app["controller"] = SDPController(config) app.on_startup.append(start_background_tasks) swagger = SwaggerDocs( app, swagger_ui_settings=SwaggerUiSettings(path="/api/doc"), title="Product controller PoC", version="1.0.0", # components="swagger.yaml", ) swagger.add_routes( [ web.get("/", home_page), web.post("/product-configure", product_configure_handle), web.post("/capture-init", capture_init_handle), web.post("/capture-done", capture_done_handle), web.post("/product-deconfigure", product_deconfigure_handle), web.get("/status", status_handle), web.get("/config", config_handle), ] ) web.run_app(app)
def main(): app = web.Application() s = SwaggerDocs( app, components="components.yaml", swagger_ui_settings=SwaggerUiSettings(path="/docs"), ) s.add_routes([web.get("/", handler, allow_head=False)]) web.run_app(app)
def main(): app = web.Application() s = SwaggerDocs( app, swagger_ui_settings=SwaggerUiSettings(path="/swagger"), redoc_ui_settings=ReDocUiSettings(path="/redoc"), rapidoc_ui_settings=RapiDocUiSettings(path="/rapidoc"), ) s.add_routes([web.get("/", handler, allow_head=True)]) web.run_app(app)
def main(): app = web.Application() s = SwaggerDocs( app, title="Example", version="1.0.0", swagger_ui_settings=SwaggerUiSettings(path="/docs"), ) s.add_routes( [ web.get("/docstring", docstring_handler, allow_head=False), web.get("/decorator", decorator_handler, allow_head=False), ] ) web.run_app(app)
def main(): app = web.Application() s = SwaggerFile( app, spec_file="petstore.yaml", swagger_ui_settings=SwaggerUiSettings(path="/docs"), ) s.add_routes( [ web.get("/pets", get_all_pets), web.get("/pets/{pet_id}", get_one_pet), web.delete("/pets/{pet_id}", delete_one_pet), web.post("/pets", create_pet), ] ) app["storage"] = {} web.run_app(app)
def main(): app = web.Application() s = SwaggerDocs( app, title="Swagger Petstore", version="1.0.0", components="components.yaml", swagger_ui_settings=SwaggerUiSettings(path="/docs"), ) s.add_routes( [ web.get("/pets", get_all_pets), web.get("/pets/{pet_id}", get_one_pet), web.delete("/pets/{pet_id}", delete_one_pet), web.post("/pets", create_pet), ] ) app["storage"] = {} web.run_app(app)
def main() -> None: settings = config.get_config() app = web.Application( client_max_size=5 * 1024**2, middlewares=[handler.response_time, handler.request_counter], ) swagger = SwaggerDocs( app, swagger_ui_settings=SwaggerUiSettings(path="/api/docs/"), title="{{cookiecutter.project_name}}", version=__version__, ) config.init_config(app, settings) app.on_startup.append(startup_handler) app.on_cleanup.append(shutdown_handler) swagger.add_routes(handler.routing_table(app)) web.run_app( app, host=settings["app"]["host"], port=settings["app"]["port"], # access_log=None, )
def set_swagger_config(self, app): """ Swagger configuration parameters loader ----------------- Args: app (web.app): Aiohhtp web app. Returns: SwaggerDocs: SwaggerDocs configuration loaded """ swagger_config = self.config['swagger'] return SwaggerDocs( app, title=swagger_config["title"], version=swagger_config["version"], swagger_ui_settings=SwaggerUiSettings( path=swagger_config["path"], layout=swagger_config["layout"], deepLinking=swagger_config["deepLinking"], displayOperationId=swagger_config["displayOperationId"], defaultModelsExpandDepth=swagger_config[ "defaultModelsExpandDepth"], defaultModelExpandDepth=swagger_config[ "defaultModelExpandDepth"], defaultModelRendering=swagger_config["defaultModelRendering"], displayRequestDuration=swagger_config["displayRequestDuration"], docExpansion=swagger_config["docExpansion"], filter=swagger_config["filter"], showExtensions=swagger_config["showExtensions"], showCommonExtensions=swagger_config["showCommonExtensions"], supportedSubmitMethods=swagger_config["test"].split(","), validatorUrl=swagger_config["validatorUrl"], withCredentials=swagger_config["withCredentials"], ), )
def main(): """Run RS21 API""" parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', dest='config', help='config file', required=True) args = parser.parse_args() app = web.Application() with open(args.config, 'r') as fd: app.cfg = yaml.safe_load(fd) app._db = DatabaseConfig.asyncmongo( app.cfg['MONGO_DB']['HOST'], app.cfg['MONGO_DB']['PORT'], app.cfg['MONGO_DB']['DB_NAME'] ) handlers = [ web.get('/api/v1/facebook', FacebookHandler), web.get('/api/v1/facebook_type_places', FacebookTypePlacesHandler), web.get('/api/v1/twitter', TwitterHandler), web.view('/api/v1/twitter/{id}', TwitterByIdHandler), web.get('/api/v1/bernallio', BernallioHandler), web.get('/api/v1/geometries', BernallioGeometriesHandler), ] swagger = SwaggerDocs( app, swagger_ui_settings=SwaggerUiSettings(path='/api/v1/docs'), title='RS21 API', version='0.1' ) swagger.add_routes(handlers) web.run_app(app, host=app.cfg['APP']['HOST'], port=int(app.cfg['APP']['PORT']))
def main(): app = web.Application() s = SwaggerDocs( app, swagger_ui_settings=SwaggerUiSettings( path="/docs", layout="BaseLayout", deepLinking=False, displayOperationId=True, defaultModelsExpandDepth=5, defaultModelExpandDepth=5, defaultModelRendering="model", displayRequestDuration=True, docExpansion="list", filter=True, showExtensions=True, showCommonExtensions=True, supportedSubmitMethods=["get"], validatorUrl=None, withCredentials=True, ), ) s.add_routes([web.get("/", handler, allow_head=True)]) web.run_app(app)
def _swagger_ui_settings(**kwargs): if "path" not in kwargs: kwargs["path"] = "/docs" return SwaggerUiSettings(**kwargs)
def __init__( self, db: DbAccess, model_handler: ModelHandler, subscription_handler: SubscriptionHandler, workflow_handler: TaskHandlerService, message_bus: MessageBus, event_sender: AnalyticsEventSender, worker_task_queue: WorkerTaskQueue, cert_handler: CertificateHandler, config_handler: ConfigHandler, cli: CLI, query_parser: QueryParser, args: Namespace, ): self.db = db self.model_handler = model_handler self.subscription_handler = subscription_handler self.workflow_handler = workflow_handler self.message_bus = message_bus self.event_sender = event_sender self.worker_task_queue = worker_task_queue self.cert_handler = cert_handler self.config_handler = config_handler self.cli = cli self.query_parser = query_parser self.args = args self.app = web.Application( # note on order: the middleware is passed in the order provided. middlewares=[ metrics_handler, auth.auth_handler(args), cors_handler, error_handler(args, event_sender), default_middleware(self), ]) self.app.on_response_prepare.append(on_response_prepare) self.merge_max_wait_time = timedelta( seconds=args.merge_max_wait_time_seconds) self.session: Optional[ClientSession] = None self.in_shutdown = False self.websocket_handler: Dict[str, Tuple[Future, web.WebSocketResponse]] = { } # type: ignore # pypy static_path = os.path.abspath(os.path.dirname(__file__) + "/../static") ui_route = ([ web.get("/ui", self.forward("/ui/index.html")), web.get("/ui/", self.forward("/ui/index.html")), web.static("/ui/", self.args.ui_path), ] if self.args.ui_path else []) tsdb_route = [web.route(METH_ANY, "/tsdb/{tail:.+}", tsdb(self)) ] if self.args.tsdb_proxy_url else [] self.app.add_routes([ # Model operations web.get("/model", self.get_model), web.get("/model/uml", self.model_uml), web.patch("/model", self.update_model), # CRUD Graph operations web.get("/graph", self.list_graphs), web.get("/graph/{graph_id}", self.get_node), web.post("/graph/{graph_id}", self.create_graph), web.delete("/graph/{graph_id}", self.wipe), # No section of the graph # TODO: deprecated. Remove it. web.post("/graph/{graph_id}/query/raw", self.raw), web.post("/graph/{graph_id}/query/explain", self.explain), web.post("/graph/{graph_id}/query/list", self.query_list), web.post("/graph/{graph_id}/query/graph", self.query_graph_stream), web.post("/graph/{graph_id}/query/aggregate", self.query_aggregation), # search the graph web.post("/graph/{graph_id}/search/raw", self.raw), web.post("/graph/{graph_id}/search/explain", self.explain), web.post("/graph/{graph_id}/search/list", self.query_list), web.post("/graph/{graph_id}/search/graph", self.query_graph_stream), web.post("/graph/{graph_id}/search/aggregate", self.query_aggregation), # maintain the graph web.patch("/graph/{graph_id}/nodes", self.update_nodes), web.post("/graph/{graph_id}/merge", self.merge_graph), web.post("/graph/{graph_id}/batch/merge", self.update_merge_graph_batch), web.get("/graph/{graph_id}/batch", self.list_batches), web.post("/graph/{graph_id}/batch/{batch_id}", self.commit_batch), web.delete("/graph/{graph_id}/batch/{batch_id}", self.abort_batch), # node specific actions web.post("/graph/{graph_id}/node/{node_id}/under/{parent_node_id}", self.create_node), web.get("/graph/{graph_id}/node/{node_id}", self.get_node), web.patch("/graph/{graph_id}/node/{node_id}", self.update_node), web.delete("/graph/{graph_id}/node/{node_id}", self.delete_node), web.patch("/graph/{graph_id}/node/{node_id}/section/{section}", self.update_node), # Subscriptions web.get("/subscribers", self.list_all_subscriptions), web.get("/subscribers/for/{event_type}", self.list_subscription_for_event), # Subscription web.get("/subscriber/{subscriber_id}", self.get_subscriber), web.put("/subscriber/{subscriber_id}", self.update_subscriber), web.delete("/subscriber/{subscriber_id}", self.delete_subscriber), web.post("/subscriber/{subscriber_id}/{event_type}", self.add_subscription), web.delete("/subscriber/{subscriber_id}/{event_type}", self.delete_subscription), web.get("/subscriber/{subscriber_id}/handle", self.handle_subscribed), # CLI web.post("/cli/evaluate", self.evaluate), web.post("/cli/execute", self.execute), web.get("/cli/info", self.cli_info), # Event operations web.get("/events", self.handle_events), # Worker operations web.get("/work/queue", self.handle_work_tasks), web.get("/work/create", self.create_work), web.get("/work/list", self.list_work), # Serve static filed web.get("", self.redirect_to_api_doc), web.static("/static", static_path), # metrics web.get("/metrics", self.metrics), # config operations web.get("/configs", self.list_configs), web.put("/config/{config_id}", self.put_config), web.get("/config/{config_id}", self.get_config), web.patch("/config/{config_id}", self.patch_config), web.delete("/config/{config_id}", self.delete_config), # config model operations web.get("/configs/validation", self.list_config_models), web.get("/configs/model", self.get_configs_model), web.patch("/configs/model", self.update_configs_model), web.put("/config/{config_id}/validation", self.put_config_validation), web.get("/config/{config_id}/validation", self.get_config_validation), # ca operations web.get("/ca/cert", self.certificate), web.post("/ca/sign", self.sign_certificate), # system operations web.get("/system/ping", self.ping), web.get("/system/ready", self.ready), *ui_route, *tsdb_route, ]) SwaggerFile( self.app, spec_file=f"{static_path}/api-doc.yaml", swagger_ui_settings=SwaggerUiSettings(path="/api-doc", layout="BaseLayout", docExpansion="none"), )
app["sim_runner"] = asyncio.Task(sim_runner(app)) app = web.Application() app["tape_library"] = Library() app.on_startup.append(start_background_tasks) app.add_routes([ web.get("/", map_page), web.get("/show.png", map_img), web.get("/log", log_page) ]) if __name__ == "__main__": swagger = SwaggerDocs( app, swagger_ui_settings=SwaggerUiSettings(path="/api/doc"), title="Tape Library Robot API", version="1.0.0", components="swagger.yaml", ) swagger.add_routes([ web.get("/load", handlers.load_handle), web.get("/unload", handlers.unload_handle), web.get("/transfer", handlers.transfer_handle), web.get("/inventory", handlers.inventory_handle), web.get("/scan", handlers.scan_handle), web.get("/sensors", handlers.sensors_handle), web.get("/config", handlers.config_handle), web.get("/state", handlers.state_handle), web.get("/park", handlers.park_handle), web.get("/lock", handlers.lock_handle),
def __add_routes(self, prefix: str) -> None: static_path = os.path.abspath(os.path.dirname(__file__) + "/../static") ui_route: List[AbstractRouteDef] = ( [web.static(f"{prefix}/ui/", self.config.api.ui_path)] if self.config.api.ui_path and Path(self.config.api.ui_path).exists() else [web.get(f"{prefix}/ui/index.html", self.no_ui)]) tsdb_route = ([ web.route(METH_ANY, prefix + "/tsdb/{tail:.+}", tsdb(self)) ] if self.config.api.tsdb_proxy_url else []) self.app.add_routes([ # Model operations web.get(prefix + "/model", self.get_model), web.get(prefix + "/model/uml", self.model_uml), web.patch(prefix + "/model", self.update_model), # CRUD Graph operations web.get(prefix + "/graph", self.list_graphs), web.get(prefix + "/graph/{graph_id}", self.get_node), web.post(prefix + "/graph/{graph_id}", self.create_graph), web.delete(prefix + "/graph/{graph_id}", self.wipe), # search the graph web.post(prefix + "/graph/{graph_id}/search/raw", self.raw), web.post(prefix + "/graph/{graph_id}/search/explain", self.explain), web.post(prefix + "/graph/{graph_id}/search/list", self.query_list), web.post(prefix + "/graph/{graph_id}/search/graph", self.query_graph_stream), web.post(prefix + "/graph/{graph_id}/search/aggregate", self.query_aggregation), # maintain the graph web.patch(prefix + "/graph/{graph_id}/nodes", self.update_nodes), web.post(prefix + "/graph/{graph_id}/merge", self.merge_graph), web.post(prefix + "/graph/{graph_id}/batch/merge", self.update_merge_graph_batch), web.get(prefix + "/graph/{graph_id}/batch", self.list_batches), web.post(prefix + "/graph/{graph_id}/batch/{batch_id}", self.commit_batch), web.delete(prefix + "/graph/{graph_id}/batch/{batch_id}", self.abort_batch), # node specific actions web.post( prefix + "/graph/{graph_id}/node/{node_id}/under/{parent_node_id}", self.create_node), web.get(prefix + "/graph/{graph_id}/node/{node_id}", self.get_node), web.patch(prefix + "/graph/{graph_id}/node/{node_id}", self.update_node), web.delete(prefix + "/graph/{graph_id}/node/{node_id}", self.delete_node), web.patch( prefix + "/graph/{graph_id}/node/{node_id}/section/{section}", self.update_node), # Subscriptions web.get(prefix + "/subscribers", self.list_all_subscriptions), web.get(prefix + "/subscribers/for/{event_type}", self.list_subscription_for_event), # Subscription web.get(prefix + "/subscriber/{subscriber_id}", self.get_subscriber), web.put(prefix + "/subscriber/{subscriber_id}", self.update_subscriber), web.delete(prefix + "/subscriber/{subscriber_id}", self.delete_subscriber), web.post(prefix + "/subscriber/{subscriber_id}/{event_type}", self.add_subscription), web.delete(prefix + "/subscriber/{subscriber_id}/{event_type}", self.delete_subscription), web.get(prefix + "/subscriber/{subscriber_id}/handle", self.handle_subscribed), # CLI web.post(prefix + "/cli/evaluate", self.evaluate), web.post(prefix + "/cli/execute", self.execute), web.get(prefix + "/cli/info", self.cli_info), # Event operations web.get(prefix + "/events", self.handle_events), # Worker operations web.get(prefix + "/work/queue", self.handle_work_tasks), web.get(prefix + "/work/create", self.create_work), web.get(prefix + "/work/list", self.list_work), # Serve static filed web.get(prefix, self.redirect_to_api_doc), web.static(prefix + "/static", static_path), # metrics web.get(prefix + "/metrics", self.metrics), # config operations web.get(prefix + "/configs", self.list_configs), web.put(prefix + "/config/{config_id}", self.put_config), web.get(prefix + "/config/{config_id}", self.get_config), web.patch(prefix + "/config/{config_id}", self.patch_config), web.delete(prefix + "/config/{config_id}", self.delete_config), # config model operations web.get(prefix + "/configs/validation", self.list_config_models), web.get(prefix + "/configs/model", self.get_configs_model), web.patch(prefix + "/configs/model", self.update_configs_model), web.put(prefix + "/config/{config_id}/validation", self.put_config_validation), web.get(prefix + "/config/{config_id}/validation", self.get_config_validation), # ca operations web.get(prefix + "/ca/cert", self.certificate), web.post(prefix + "/ca/sign", self.sign_certificate), # system operations web.get(prefix + "/system/ping", self.ping), web.get(prefix + "/system/ready", self.ready), # forwards web.get(prefix + "/tsdb", self.forward("/tsdb/")), web.get(prefix + "/ui", self.forward("/ui/index.html")), web.get(prefix + "/ui/", self.forward("/ui/index.html")), *ui_route, *tsdb_route, ]) SwaggerFile( self.app, spec_file=f"{static_path}/api-doc.yaml", swagger_ui_settings=SwaggerUiSettings(path=prefix + "/api-doc", layout="BaseLayout", docExpansion="none"), )
def main(): app = web.Application() s = SwaggerDocs(app, swagger_ui_settings=SwaggerUiSettings(path="/docs")) s.add_routes([web.view("/r/{param_id}", View)]) web.run_app(app)