example_b.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. import bottle
  3. import hapic
  4. from example import HelloResponseSchema, HelloPathSchema, HelloJsonSchema
  5. from hapic.hapic import MarshmallowOutputProcessor, BottleContext, \
  6. MarshmallowPathInputProcessor, MarshmallowJsonInputProcessor
  7. def bob(f):
  8. def boby(*args, **kwargs):
  9. return f
  10. return boby
  11. @hapic.with_api_doc_bis()
  12. @bottle.route('/hello/<name>')
  13. @hapic.input(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  14. @hapic.output(HelloResponseSchema(), MarshmallowOutputProcessor())
  15. @bob
  16. def hello(name: str):
  17. return "Hello {}!".format(name)
  18. @hapic.with_api_doc_bis()
  19. @bottle.route('/hello2/<name>')
  20. @hapic.input(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  21. @hapic.input(HelloJsonSchema(), MarshmallowJsonInputProcessor(), context=BottleContext()) # nopep8
  22. @hapic.output(HelloResponseSchema())
  23. @bob
  24. def hello2(name: str):
  25. return "Hello {}!".format(name)
  26. @hapic.with_api_doc_bis()
  27. @bottle.route('/hello3/<name>')
  28. @hapic.output(HelloResponseSchema())
  29. def hello3(name: str):
  30. return "Hello {}!".format(name)
  31. hapic.generate_doc()
  32. bottle.run(host='localhost', port=8080, debug=True)
  33. @bottle.route('/hello/<name>')
  34. @hapic.input_body(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  35. @hapic.input_header(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  36. @hapic.input_query(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  37. @hapic.input_path(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  38. @hapic.output(HelloResponseSchema(), MarshmallowOutputProcessor())
  39. def hello(name: str, hapic_data):
  40. return "Hello {}!".format(name)
  41. @hapic.with_api_doc_bis()
  42. @bottle.route('/hello/<name>')
  43. @hapic.input(HelloPathSchema(), MarshmallowPathInputProcessor(), context=BottleContext()) # nopep8
  44. @hapic.output(HelloResponseSchema(), MarshmallowOutputProcessor())
  45. @bob
  46. def hello(name: str):
  47. return "Hello {}!".format(name)