mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-31 02:00:34 -05:00
* 📝 Add docs recommending Union over Optional * 📝 Update docs recommending Union over Optional * 📝 Update source examples for docs, recommend Union over Optional * 📝 Update highlighted lines with updated source examples * 📝 Update highlighted lines in Markdown with recent code changes * 📝 Update docs, use Union instead of Optional * ♻️ Update source examples to recommend Union over Optional * 🎨 Update highlighted code in Markdown after moving from Optional to Union
20 lines
363 B
Python
20 lines
363 B
Python
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class UserIn(BaseModel):
|
|
username: str
|
|
password: str
|
|
email: EmailStr
|
|
full_name: Union[str, None] = None
|
|
|
|
|
|
# Don't do this in production!
|
|
@app.post("/user/", response_model=UserIn)
|
|
async def create_user(user: UserIn):
|
|
return user
|