33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
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 |