Coverage for docs_src/extending_openapi/tutorial001.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1from fastapi import FastAPI 1abcdef
2from fastapi.openapi.utils import get_openapi 1abcdef
4app = FastAPI() 1abcdef
7@app.get("/items/") 1abcdef
8async def read_items(): 1abcdef
9 return [{"name": "Foo"}] 1mnopqr
12def custom_openapi(): 1abcdef
13 if app.openapi_schema: 1ghijkl
14 return app.openapi_schema 1ghijkl
15 openapi_schema = get_openapi( 1ghijkl
16 title="Custom title",
17 version="2.5.0",
18 summary="This is a very custom OpenAPI schema",
19 description="Here's a longer description of the custom **OpenAPI** schema",
20 routes=app.routes,
21 )
22 openapi_schema["info"]["x-logo"] = { 1ghijkl
23 "url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
24 }
25 app.openapi_schema = openapi_schema 1ghijkl
26 return app.openapi_schema 1ghijkl
29app.openapi = custom_openapi 1abcdef