Add Book schema

This commit is contained in:
Backend IM Bot 2025-03-26 17:27:01 +01:00
parent 9600b23c96
commit 013efd1dd6

51
schemas/book.py Normal file
View File

@ -0,0 +1,51 @@
from pydantic import BaseModel, Field
# Base Schema
class BookBase(BaseModel):
title: str = Field(..., description="Book title")
author: str = Field(..., description="Book author")
description: str = Field(None, description="Book description")
published_year: int = Field(None, description="Year the book was published")
class Config:
schema_extra = {
"example": {
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"description": "A novel about the decadence of the Jazz Age.",
"published_year": 1925
}
}
# Create Schema
class BookCreate(BookBase):
isbn: str = Field(..., description="Book ISBN number")
class Config:
schema_extra = {
"example": {
"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"description": "A classic novel about racial injustice.",
"published_year": 1960,
"isbn": "978-0060935467"
}
}
# Response Schema
class Book(BookBase):
id: int = Field(..., description="Book ID")
isbn: str = Field(..., description="Book ISBN number")
class Config:
orm_mode = True
schema_extra = {
"example": {
"id": 1,
"title": "1984",
"author": "George Orwell",
"description": "A dystopian novel about totalitarianism.",
"published_year": 1949,
"isbn": "978-0451524935"
}
}