32 lines
894 B
Python
32 lines
894 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
class CarBase(BaseModel):
|
|
name: str = Field(..., description="Car's name")
|
|
color: str = Field(..., description="Car's color")
|
|
|
|
class CarCreate(CarBase):
|
|
pass
|
|
|
|
class CarUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, description="Car's name")
|
|
color: Optional[str] = Field(None, description="Car's color")
|
|
|
|
class CarSchema(CarBase):
|
|
id: UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
|
"name": "Tesla Model 3",
|
|
"color": "red",
|
|
"created_at": "2023-01-01T12:00:00",
|
|
"updated_at": "2023-01-01T12:00:00"
|
|
}
|
|
} |