Add Book schema

This commit is contained in:
Backend IM Bot 2025-03-28 13:18:31 +00:00
parent 0b5aa1d1a3
commit bd1a14a143

33
schemas/book.py Normal file
View File

@ -0,0 +1,33 @@
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")
description: Optional[str] = Field(None, description="Book description")
isbn: str = Field(..., min_length=10, max_length=13, description="Book ISBN")
publication_year: Optional[int] = Field(None, gt=1000, lt=2100, description="Year of publication")
publisher: Optional[str] = Field(None, max_length=100, description="Book publisher")
page_count: Optional[int] = Field(None, gt=0, description="Number of pages")
language: Optional[str] = Field(None, max_length=50, description="Book language")
class BookCreate(BookBase):
class Config:
schema_extra = {
"example": {
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"description": "A story of decadence and excess",
"isbn": "9780743273565",
"publication_year": 1925,
"publisher": "Charles Scribner's Sons",
"page_count": 180,
"language": "English"
}
}
class Book(BookBase):
id: int = Field(..., description="Book ID")
class Config:
orm_mode = True