Add support for function return type annotations to declare the response_model (#1436)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Yurii Karabas
2023-01-07 15:45:48 +02:00
committed by GitHub
parent efc12c5cdb
commit d0573f5713
18 changed files with 1368 additions and 58 deletions

View File

@@ -0,0 +1,21 @@
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class BaseUser(BaseModel):
username: str
email: EmailStr
full_name: Union[str, None] = None
class UserIn(BaseUser):
password: str
@app.post("/user/")
async def create_user(user: UserIn) -> BaseUser:
return user