โ ๐¶
Warning
๐ ๐ ๐ง โ. ๐ ๐ฒ ๐ช ๐ถ โซ๏ธ.
๐ฅ ๐ ๐ ๐ฐ - ๐ฉโ๐ป ๐ฆฎ, ๐ ๐ช ๐ฒ ๐ถ ๐ ๐.
๐ฅ ๐ โช ๐ญ ๐ ๐ ๐ช ๐ ๐ ๐ ๐, ๐ฃ ๐.
๐ค ๐ผ ๐โ ๐ ๐ช ๐ช ๐ ๐ ๐ ๐.
๐ ๐ ๐ ๐ ๐ โ.
๐ ๐ ๏ธ¶
๐ (๐ข) ๐ ๏ธ, โฉ.
FastAPI
๐ธ (๐) โ๏ธ .openapi()
๐ฉโ๐ฌ ๐ ๐ ๐จ ๐ ๐.
๐ ๐ธ ๐ ๐, โก ๐ ๏ธ /openapi.json
(โ๏ธ โซ๏ธโ ๐ โ ๐ openapi_url
) ยฎ.
โซ๏ธ ๐จ ๐ป ๐จ โฎ๏ธ ๐ ๐ธ .openapi()
๐ฉโ๐ฌ.
๐ข, โซ๏ธโ ๐ฉโ๐ฌ .openapi()
๐จ โ
๐ .openapi_schema
๐ ๐ฅ โซ๏ธ โ๏ธ ๐ & ๐จ ๐ซ.
๐ฅ โซ๏ธ ๐ซ, โซ๏ธ ๐ ๐ซ โ๏ธ ๐ ๐ข fastapi.openapi.utils.get_openapi
.
& ๐ ๐ข get_openapi()
๐จ ๐ข:
title
: ๐ ๐, ๐ฆ ๐ฉบ.version
: โฌ ๐ ๐ ๏ธ, โ2.5.0
.openapi_version
: โฌ ๐ ๐ง โ๏ธ. ๐ข, โช:3.0.2
.description
: ๐ ๐ ๐ ๏ธ.routes
: ๐ ๐ฃ, ๐ซ ๐ ยฎ โก ๐ ๏ธ. ๐ซ โ โช๏ธโก๏ธapp.routes
.
๐ ๐ข¶
โ๏ธ โน ๐, ๐ ๐ช โ๏ธ ๐ ๐ ๐ข ๐ ๐ ๐ & ๐ ๐ ๐ ๐ ๐ ๐ช.
๐ผ, โก๏ธ ๐ฎ ๐ ๐ โ ๐ ๐ ๐ฑ.
๐ FastAPI¶
๐ฅ, โ ๐ ๐ FastAPI ๐ธ ๐:
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Custom title",
version="2.5.0",
summary="This is a very custom OpenAPI schema",
description="Here's a longer description of the custom **OpenAPI** schema",
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
๐ ๐ ๐¶
โคด๏ธ, โ๏ธ ๐ ๐ ๐ข ๐ ๐ ๐, ๐ custom_openapi()
๐ข:
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Custom title",
version="2.5.0",
summary="This is a very custom OpenAPI schema",
description="Here's a longer description of the custom **OpenAPI** schema",
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
๐ ๐ ๐¶
๐ ๐ ๐ช ๐ฎ ๐ โ, โ ๐ x-logo
info
"๐" ๐ ๐:
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Custom title",
version="2.5.0",
summary="This is a very custom OpenAPI schema",
description="Here's a longer description of the custom **OpenAPI** schema",
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
๐พ ๐ ๐¶
๐ ๐ช โ๏ธ ๐ .openapi_schema
"๐พ", ๐ช ๐ ๐ ๐.
๐ ๐, ๐ ๐ธ ๐ ๐ซ โ๏ธ ๐ ๐ ๐ ๐ฐ ๐ฉโ๐ป ๐ ๐ ๐ ๏ธ ๐ฉบ.
โซ๏ธ ๐ ๐ ๐ด ๐, & โคด๏ธ ๐ ๐พ ๐ ๐ โ๏ธ โญ ๐จ.
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Custom title",
version="2.5.0",
summary="This is a very custom OpenAPI schema",
description="Here's a longer description of the custom **OpenAPI** schema",
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
๐ ๐ฉโ๐ฌ¶
๐ ๐ ๐ช โ .openapi()
๐ฉโ๐ฌ โฎ๏ธ ๐ ๐ ๐ข.
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Custom title",
version="2.5.0",
summary="This is a very custom OpenAPI schema",
description="Here's a longer description of the custom **OpenAPI** schema",
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
โ โซ๏ธ¶
๐ ๐ ๐ถ http://127.0.0.1:8000/redoc ๐ ๐ ๐ ๐ ๐ โ๏ธ ๐ ๐ ๐ฑ (๐ ๐ผ, FastAPI'โ ๐ฑ):