async def test_get( uid: int = Query.i(description="user id", gt=10, lt=1000), user_name: str = Query.i(description="user name", min_length=2, max_length=4), email: str = Query.i(default="*****@*****.**", description="user email"), age: int = Path.i(description="age"), sex: SexEnum = Query.i(description="sex"), multi_user_name: List[str] = MultiQuery.i(description="user name", min_length=2, max_length=4), ) -> response.HTTPResponse: """Test Field""" return response.json({ "code": 0, "msg": "", "data": { "uid": uid, "user_name": user_name, "email": email, "age": age, "sex": sex.value, "multi_user_name": multi_user_name, }, })
async def get( self, uid: int = Query.i(description="user id", gt=10, lt=1000), user_name: str = Query.i(description="user name", min_length=2, max_length=4), email: str = Query.i(default="*****@*****.**", description="user email"), model: UserOtherModel = Query.i(), ) -> JSONResponse: """Text Pydantic Model and Field""" return_dict = {"uid": uid, "user_name": user_name, "email": email, "age": model.age} return JSONResponse({"code": 0, "msg": "", "data": return_dict})
async def test_check_param( uid: int = Query.i(description="user id", gt=10, lt=1000), email: Optional[str] = Query.i(default="*****@*****.**", description="user email"), user_name: Optional[str] = Query.i(None, description="user name", min_length=2, max_length=4), alias_user_name: Optional[str] = Query.i(None, description="user name", min_length=2, max_length=4), age: int = Query.i(description="age", gt=1, lt=100), birthday: Optional[str] = Query.i(None, description="birthday"), sex: SexEnum = Query.i(description="sex"), ) -> response.HTTPResponse: """Test check param""" return response.json({ "code": 0, "msg": "", "data": { "birthday": birthday, "uid": uid, "user_name": user_name or alias_user_name, "email": email, "age": age, "sex": sex.value, }, })
async def test_depend( request: Request, model: UserModel = Query.i(), depend_tuple: Tuple[str, int] = Depends.i(demo_depend), ) -> response.HTTPResponse: """Test Method:Post request, Pydantic Model""" assert request is not None, "Not found request" return_dict = model.dict() return_dict.update({"user_agent": depend_tuple[0], "age": depend_tuple[1]}) return response.json({"code": 0, "msg": "", "data": return_dict})
async def test_check_resp( uid: int = Query.i(description="user id", gt=10, lt=1000), email: Optional[str] = Query.i(default="*****@*****.**", description="user email"), user_name: Optional[str] = Query.i(None, description="user name", min_length=2, max_length=4), age: int = Query.i(description="age", gt=1, lt=100), display_age: int = Query.i(0, description="display_age"), ) -> JSONResponse: """Test check param""" return_dict: dict = { "code": 0, "msg": "", "data": { "uid": uid, "user_name": user_name, "email": email, }, } if display_age is 1: return_dict["data"]["age"] = age return JSONResponse(return_dict)
class UserModel(BaseModel): uid: int = Query.i(description="user id", gt=10, lt=1000) user_name: str = Query.i(description="user name", min_length=2, max_length=4)
class TestPaitModel(PaitBaseModel): uid: int = Query.i(description="user id", gt=10, lt=1000) user_name: str = Query.i(description="user name", min_length=2, max_length=4) user_agent: str = Header.i(alias="user-agent", description="user agent") age: int = Body.i(description="age", gt=1, lt=100)