You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

5 years ago
  1. # -*- coding: utf-8 -*-
  2. import json
  3. from fastapi.openapi.docs import get_swagger_ui_html
  4. from odoo import http, _
  5. from ..openapi import apiroute
  6. from ..openapi import oapi
  7. class OpenApiTest(http.Controller):
  8. @http.route(['/oapi/tst1',], type='http', auth="user", website=True)
  9. def tst1(self, **kw):
  10. return "tst1"
  11. @oapi.get('/oapi/tst2')
  12. @http.route(['/oapi/tst2',], type='http', auth="user", website=True)
  13. def tst2(self):
  14. return 'ok test2'
  15. @oapi.api_route('/oapi/tst3')
  16. @http.route(['/oapi/tst3',], type='http', auth="user", website=True)
  17. def tst3(self, par1="abc"):
  18. return par1
  19. @oapi.api_route('/oapi/tst4')
  20. @http.route(['/oapi/tst4', ], type='http', auth="user", website=True)
  21. def tst4(self,par1="444"):
  22. return par1
  23. @apiroute('/oapi/tst5')
  24. def tst5(self, par1="555"):
  25. return par1
  26. @http.route(['/oapi/api',], type='http', auth="user", website=True)
  27. def api(self, **kw):
  28. return json.dumps(oapi.openapi())
  29. # wynik możesz skopiować do https://editor.swagger.io/
  30. @http.route(['/oapi/docs',], type='http', auth="user", website=True)
  31. def api_UI(self, **kw):
  32. response = get_swagger_ui_html(openapi_url = '/oapi/api', title = 'tytuł')
  33. return response.body