example_b.py 2.1KB

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