Coverage for docs_src/response_model/tutorial003.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from typing import Any, Union 1abcde

2 

3from fastapi import FastAPI 1abcde

4from pydantic import BaseModel, EmailStr 1abcde

5 

6app = FastAPI() 1abcde

7 

8 

9class UserIn(BaseModel): 1abcde

10 username: str 1abcde

11 password: str 1abcde

12 email: EmailStr 1abcde

13 full_name: Union[str, None] = None 1abcde

14 

15 

16class UserOut(BaseModel): 1abcde

17 username: str 1abcde

18 email: EmailStr 1abcde

19 full_name: Union[str, None] = None 1abcde

20 

21 

22@app.post("/user/", response_model=UserOut) 1abcde

23async def create_user(user: UserIn) -> Any: 1abcde

24 return user 1abcde