def test_get_swagger_schema_altered_basepath(self): bottle_app = Bottle() spec_with_basepath = dict(self.SWAGGER_DEF) spec_with_basepath['basePath'] = "/api/1.0" bottle_app.install(SwaggerPlugin(spec_with_basepath)) test_app = TestApp(bottle_app) response = test_app.get("/api/1.0" + SwaggerPlugin.DEFAULT_SWAGGER_SCHEMA_SUBURL) self.assertEqual(response.json, spec_with_basepath)
def init_swagger(): this_dir = os.path.dirname(os.path.abspath(__file__)) with open("{}/swagger/swagger.yml".format(this_dir)) as f: swagger_def = yaml.load(f) swagger_plugin = SwaggerPlugin(swagger_def, ignore_undefined_api_routes=True, serve_swagger_ui=True) install(swagger_plugin)
def build_app(database_url): pool = create_green_psycopg_pool(database_url) app = Bottle() attach_api_routes(app, pool) attach_view_routes(app, pool) app.install( SwaggerPlugin(load_swagger_spec(), serve_swagger_ui=True, exception_handler=api_exception_handler)) app.install(app_exception_plugin) return app
def main(): config.init() app.mount("/webapp/answer/", answer) app.mount("/webapp/add/", add_d) app.install( SwaggerPlugin(swagger_def, validate_swagger_spec=False, serve_swagger_ui=True, swagger_ui_suburl="/swagger/")) sys.exit( app.run( server="gunicorn", host=config.host(), port=config.port(), debug=True, ))
def _make_security_swagger_plugin(self, *args, **kwargs): return SwaggerPlugin(self.SWAGGER_DEF_WITH_SECURITY, *args, **kwargs)
def _make_swagger_plugin(self, *args, **kwargs): return SwaggerPlugin(self.SWAGGER_DEF, *args, **kwargs)
log.addHandler(stream_handler) log.addHandler(rotating_file_handler) # Bottle app = Bottle() service = EUNlgService(random_seed=4551546, force_cache_refresh=args.force_cache_refresh, planner=args.planner) # Swagger with open(Path(__file__).parent / ".." / "swagger.yaml", "r") as file_handle: swagger_def = yaml.load(file_handle, Loader=yaml.FullLoader) app.install( SwaggerPlugin(swagger_def, serve_swagger_ui=True, swagger_ui_suburl="/documentation/", validate_requests=False)) # Allow for trailing slash in request URLS @app.hook("before_request") def strip_path(): # Needs to be special-cased for /documentation/ 'cause bottle-swagger is weird about it. if "/documentation" not in request.environ["PATH_INFO"]: request.environ["PATH_INFO"] = request.environ["PATH_INFO"].rstrip("/") # # END INIT # def allow_cors(opts):