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.

44 lines
1.2 KiB

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