import typing
from fastapi import FastAPI, Query
app = FastAPI()
'''
查询参数使用Query校验
类似路由转换使用Path校验
物品名称最小3位,最大10位
default=None 参数为可选项,否则为必选项
default=... 设置必选项
'''
@app.get("/items")
def info(name: typing.Optional[str] = Query(min_length=3, max_length=10,
description="物品信息",
default="王小明"),
age : int = Query(gt=18)):
return {"name": name,"age":age}
标签:11,name,default,FastAPI,age,校验,Query
From: https://www.cnblogs.com/leoshi/p/17249465.html