from pydantic import BaseModel, Field from typing import Optional class BookBase(BaseModel): title: str = Field(..., min_length=1, max_length=200, description="Book title") author: str = Field(..., min_length=1, max_length=100, description="Book author") isbn: str = Field(..., min_length=10, max_length=13, description="Book ISBN") publication_year: int = Field(..., gt=0, lt=2100, description="Year of publication") publisher: str = Field(..., min_length=1, max_length=100, description="Book publisher") description: Optional[str] = Field(None, max_length=1000, description="Book description") language: str = Field(..., min_length=2, max_length=50, description="Book language") page_count: int = Field(..., gt=0, description="Number of pages") genre: str = Field(..., min_length=1, max_length=50, description="Book genre") is_available: bool = Field(default=True, description="Book availability status") class BookCreate(BookBase): class Config: schema_extra = { "example": { "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "isbn": "9780743273565", "publication_year": 1925, "publisher": "Charles Scribner's Sons", "description": "A story of the fabulously wealthy Jay Gatsby", "language": "English", "page_count": 180, "genre": "Fiction", "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", "isbn": "9780743273565", "publication_year": 1925, "publisher": "Charles Scribner's Sons", "description": "A story of the fabulously wealthy Jay Gatsby", "language": "English", "page_count": 180, "genre": "Fiction", "is_available": True } }