29 lines
1011 B
Python
29 lines
1011 B
Python
from pydantic import BaseModel, Field
|
|
from datetime import datetime
|
|
|
|
class BookBase(BaseModel):
|
|
title: str = Field(..., description="Book title")
|
|
author: str = Field(..., description="Book author", index=True)
|
|
description: str | None = Field(None, description="Book description")
|
|
page_count: int = Field(..., gt=0, description="Number of pages")
|
|
published_date: datetime = Field(..., description="Publication date")
|
|
isbn: str = Field(..., description="ISBN number", index=True)
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
class BookCreate(BookBase):
|
|
pass
|
|
|
|
class BookResponse(BookBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"title": "The Great Gatsby",
|
|
"author": "F. Scott Fitzgerald",
|
|
"description": "A novel about the decadence of the Jazz Age.",
|
|
"page_count": 180,
|
|
"published_date": "1925-04-10T00:00:00",
|
|
"isbn": "978-0743273565"
|
|
}
|
|
} |