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.

51 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import functools
  2. from fastapi import FastAPI
  3. from fastapi.openapi.utils import get_openapi
  4. def custom_openapi():
  5. if oapi.openapi_schema:
  6. return oapi.openapi_schema
  7. openapi_schema = get_openapi(
  8. title="Custom title",
  9. version="2.5.0",
  10. description="This is a very custom OpenAPI schema",
  11. routes=oapi.routes,
  12. )
  13. openapi_schema["info"]["x-logo"] = {
  14. "url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
  15. }
  16. oapi.openapi_schema = openapi_schema
  17. return oapi.openapi_schema
  18. oapi = FastAPI()
  19. oapi.openapi = custom_openapi
  20. def apiroute(route=None, **kw):
  21. routing = kw.copy()
  22. def apidecorator(f):
  23. if route:
  24. if isinstance(route, list):
  25. routes = route
  26. else:
  27. routes = [route]
  28. routing["routes"] = routes
  29. @functools.wraps(f)
  30. def response_wrap(*args, **kw):
  31. response = f(*args, **kw)
  32. return response
  33. oapi.add_api_route(routes[0], f, include_in_schema=True)
  34. response_wrap.routing = routing
  35. response_wrap.original_func = f
  36. return response_wrap
  37. return apidecorator
  38. #