mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-29 09:08:25 -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
38 lines
502 B
Python
38 lines
502 B
Python
from typing import List, Union
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class ItemBase(BaseModel):
|
|
title: str
|
|
description: Union[str, None] = None
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
pass
|
|
|
|
|
|
class Item(ItemBase):
|
|
id: int
|
|
owner_id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
email: str
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
password: str
|
|
|
|
|
|
class User(UserBase):
|
|
id: int
|
|
is_active: bool
|
|
items: List[Item] = []
|
|
|
|
class Config:
|
|
orm_mode = True
|