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.

41 lines
962 B

5 years ago
  1. # pip install fastapi
  2. # pip install email-validator
  3. # pip install pydantic
  4. # pip install starlette
  5. # pip install uvicorn
  6. import uvicorn
  7. from fastapi import FastAPI
  8. from fastapi.openapi.utils import get_openapi
  9. app = FastAPI()
  10. @app.get("/items/")
  11. async def read_items():
  12. return [{"name": "Foo"}]
  13. def custom_openapi():
  14. if app.openapi_schema:
  15. return app.openapi_schema
  16. openapi_schema = get_openapi(
  17. title="Custom title",
  18. version="2.5.0",
  19. description="This is a very custom OpenAPI schema",
  20. routes=app.routes,
  21. )
  22. openapi_schema["info"]["x-logo"] = {
  23. "url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
  24. }
  25. app.openapi_schema = openapi_schema
  26. return app.openapi_schema
  27. app.openapi = custom_openapi
  28. if __name__ == '__main__':
  29. print("see http://127.0.0.1:8000/docs")
  30. uvicorn.run(app, #'server:app',
  31. host='127.0.0.1', port=8000, reload=True)