# FastAPI 接口文档配置相关

### 接口设置

* **Title** 标题
* **Description** API 的描述
* **Version** API 版本
* 更多+——> [元数据和文档 URL - FastAPI](https://fastapi.tiangolo.com/zh/tutorial/metadata/)
* ### 文档 URLs

  你可以配置两个文档用户界面，包括：

  * **Swagger UI**：服务于 `/docs`。
    * 可以使用参数 `docs_url` 设置它的 URL。
    * 可以通过设置 `docs_url=None` 禁用它。
  * ReDoc：服务于 `/redoc`。
    * 可以使用参数 `redoc_url` 设置它的 URL。
    * 可以通过设置 `redoc_url=None` 禁用它。

```python
description = """
ChimichangApp API helps you do awesome stuff. 🚀

## Items

You can **read items**.

## Users

You will be able to:

* **Create users** (_not implemented_).
* **Read users** (_not implemented_).
"""






app = FastAPI(
    title="ChimichangApp",
    description=description,
    version="0.0.1",
    terms_of_service="http://example.com/terms/",
    contact={
        "name": "Deadpoolio the Amazing",
        "url": "http://x-force.example.com/contact/",
        "email": "dp@x-force.example.com",
    },
    license_info={
        "name": "Apache 2.0",
        "url": "https://www.apache.org/licenses/LICENSE-2.0.html",
    },
)
```

### 某些接口相关设置

* 比如有些接口需要分组 ---> tags
* 接口添加描述： ---> description
* 把注释展现到接口里 ---> summary
* 标注接口启用 ----> deprecated

```python
from fastapi import FastAPI
app = FastAPI()
@app.post("/login/", tags=["login"], description="这是",summary="这是登录模块")
def login(username: str,password:str):
    """
    登录
    - param username:  用户名
    - param password:  密码
    - return: 返回是否成功
    """
    if username == "admin" and password=="admin":
        return "success"
    return {"name": username}

@app.post("/regin/", tags=["login"], deprecated=True)
def regin(username: str,password:str):
    return {"name": username}
```
