mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-12 09:49:06 -04:00
✨ 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:
21
docs_src/response_model/tutorial003_01.py
Normal file
21
docs_src/response_model/tutorial003_01.py
Normal 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
|
||||
Reference in New Issue
Block a user