} kwargs = {"validated_data": {"name": "bob"}, "name": "bob"} @hapic.with_api_doc() # @hapic.ext.bottle.bottle_context() # @hapic.error_schema(ErrorResponseSchema()) @hapic.input_path(HelloPathSchema()) @hapic.output_body(HelloResponseSchema()) def hello3(self, name: str, hapic_data: HapicData): return {"sentence": "Hello !", "name": name} def bind(self, app): pass app.add_url_rule("/hello/<name>", "hello", self.hello) app.add_url_rule("/hello/<name>", "hello2", self.hello2, methods=["POST"]) app.add_url_rule("/hello3/<name>", "hello3", self.hello3) controllers = Controllers() controllers.bind(app) hapic.set_context( FlaskContext(app, default_error_builder=MarshmallowDefaultErrorBuilder())) hapic.add_documentation_view("/api-doc", "DOC", "Generated doc") print(json.dumps(hapic.generate_doc())) app.run(host="localhost", port=8080, debug=True)
@hapic.output_body(HelloResponseSchema()) def hello3(self, name: str, hapic_data: HapicData): return {"sentence": "Hello !", "name": name} @hapic.with_api_doc() @hapic.input_files(HelloFileSchema()) @hapic.output_file(["image/jpeg"]) def hellofile(self, hapic_data: HapicData): return hapic_data.files["myfile"] def bind(self, app): app.route("/hello/<name>", callback=self.hello) app.route("/hello/<name>", callback=self.hello2, method="POST") app.route("/hello3/<name>", callback=self.hello3) app.route("/hellofile", callback=self.hellofile) app = bottle.Bottle() controllers = Controllers() controllers.bind(app) hapic.set_context( BottleContext(app, default_error_builder=MarshmallowDefaultErrorBuilder())) print( yaml.dump(json.loads(json.dumps(hapic.generate_doc())), default_flow_style=False)) app.run(host="localhost", port=8080, debug=True)
MarshmallowJsonInputProcessor(), context=BottleContext()) # nopep8 @hapic.output_body(HelloResponseSchema()) @bob def hello2(name: str): return "Hello {}!".format(name) @hapic.with_api_doc_bis() @bottle.route('/hello3/<name>') @hapic.output_body(HelloResponseSchema()) def hello3(name: str): return "Hello {}!".format(name) hapic.generate_doc() bottle.run(host='localhost', port=8080, debug=True) @bottle.route('/hello/<name>') @hapic.input_body(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8 @hapic.input_header(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8 @hapic.input_query(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8 @hapic.input_path(HelloPathSchema(), MarshmallowPathInputProcessor(),