Coverage for docs_src / extra_models / tutorial001_py310.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from fastapi import FastAPI 1adbc
2from pydantic import BaseModel, EmailStr 1adbc
4app = FastAPI() 1adbc
7class UserIn(BaseModel): 1adbc
8 username: str 1abc
9 password: str 1abc
10 email: EmailStr 1abc
11 full_name: str | None = None 1adbc
14class UserOut(BaseModel): 1adbc
15 username: str 1abc
16 email: EmailStr 1abc
17 full_name: str | None = None 1adbc
20class UserInDB(BaseModel): 1adbc
21 username: str 1abc
22 hashed_password: str 1abc
23 email: EmailStr 1abc
24 full_name: str | None = None 1adbc
27def fake_password_hasher(raw_password: str): 1adbc
28 return "supersecret" + raw_password 1efgh
31def fake_save_user(user_in: UserIn): 1adbc
32 hashed_password = fake_password_hasher(user_in.password) 1efgh
33 user_in_db = UserInDB(**user_in.model_dump(), hashed_password=hashed_password) 1efgh
34 print("User saved! ..not really") 1efgh
35 return user_in_db 1efgh
38@app.post("/user/", response_model=UserOut) 1adbc
39async def create_user(user_in: UserIn): 1adbc
40 user_saved = fake_save_user(user_in) 1efgh
41 return user_saved 1efgh