您可以在FastAPI应用程序中配置几件事。
标题,描述和版本
您可以设置:
标题:在OpenAPI和自动API文档用户界面中,用作API的标题/名称。
Description:OpenAPI和自动API文档UI中对API的描述。
版本:API的版本,例如
v2
或
2.5.0
。
例如,如果您具有应用程序的先前版本(也使用OpenAPI),则很有用。
要设置这些参数,使用这些参数
title
,
description
以及
version
:
from fastapi import FastAPI
app = FastAPI(
title="My Super Project",
description="This is a very fancy project, with auto docs for the API and everything",
version="2.5.0",
)
@app.get("/items/")
async def read_items():
return [{"name": "Foo"}]
使用此配置,自动API文档将如下所示:
OpenAPI的URL