from pydantic import BaseModel, Field from typing import Optional class BookBase(BaseModel): title: str = Field(..., min_length=1, description="Book title") author: str = Field(..., min_length=1, description="Book author") description: Optional[str] = Field(None, description="Book description") isbn: str = Field(..., description="Book ISBN number") price: int = Field(..., gt=0, description="Book price") quantity: int = Field(0, ge=0, description="Available quantity") is_available: bool = Field(True, description="Book availability status") class BookCreate(BookBase): class Config: schema_extra = { "example": { "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "description": "A story of decadence and excess", "isbn": "978-0743273565", "price": 999, "quantity": 50, "is_available": True } } class Book(BookBase): id: int = Field(..., description="Book ID") class Config: orm_mode = True schema_extra = { "example": { "id": 1, "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "description": "A story of decadence and excess", "isbn": "978-0743273565", "price": 999, "quantity": 50, "is_available": True } }