if __name__ __main__ :
uvicorn.run(app 31_metadata:app , host 127.0.0.1 , port 8080, reload True, debug True)
查看 Swagger API
常见元数据参数
参数类型描述titlestrAPI 的标题descriptionstrAPI 的描述 可以使用 MarkDown 格式versionstrAPI 的版本 是自己应用程序的版本 不是 OpenAPI 的版本terms_of_servicestr服务条款的 URL 如果提供 这必须是一个 URLcontactdictAPI 的联系信息 它可以包含多个字段license_infodictAPI 的许可信息 它可以包含多个字段
contact 字段
参数类型描述namestr联系人/组织的识别名称urlstr指向联系信息的 URL 必须采用 URL 格式emailstr联系人/组织的电子邮件地址 必须采用电子邮件地址的格式
license_info 字段
参数类型描述namestr必传(如果设置了 license_info) API 的许可证名称urlstrAPI 的许可证的 URL 必须采用 URL 格式
为 tags 创建元数据
之前在讲路径操作装饰器的配置项的时候 有提过 tags 这个参数 这里来讲下给不同 tags 创建元数据
from fastapi import FastAPI
tags_metadata [
# name 要对应 tags 参数值
name : users ,
description : Operations with users. The **login** logic is also here. ,
name : items ,
description : Manage items. So _fancy_ they have their own docs. ,
externalDocs : {
description : Items external docs ,
url : https://www.cnblogs.com/poloyy/ ,
# 添加 openapi_tags 参数
app FastAPI(openapi_tags tags_metadata)