Coverage for docs_src / extra_models / tutorial002_py310.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI 1abc
2from pydantic import BaseModel, EmailStr 1abc
4app = FastAPI() 1abc
7class UserBase(BaseModel): 1abc
8 username: str 1abc
9 email: EmailStr 1abc
10 full_name: str | None = None 1abc
13class UserIn(UserBase): 1abc
14 password: str 1abc
17class UserOut(UserBase): 1abc
18 pass 1abc
21class UserInDB(UserBase): 1abc
22 hashed_password: str 1abc
25def fake_password_hasher(raw_password: str): 1abc
26 return "supersecret" + raw_password 1def
29def fake_save_user(user_in: UserIn): 1abc
30 hashed_password = fake_password_hasher(user_in.password) 1def
31 user_in_db = UserInDB(**user_in.model_dump(), hashed_password=hashed_password) 1def
32 print("User saved! ..not really") 1def
33 return user_in_db 1def
36@app.post("/user/", response_model=UserOut) 1abc
37async def create_user(user_in: UserIn): 1abc
38 user_saved = fake_save_user(user_in) 1def
39 return user_saved 1def