---
Creates Pydantic schemas with CamelModel for FastAPI CRUD operations.
/plugin marketplace add adelabdelgawad/full-stack/plugin install fastapi-patterns@full-stackIMPORTANT: When this command is invoked, you MUST actually CREATE the file. Do NOT just show the template.
If not provided, ask the user: "What is the resource name? (e.g., 'product', 'order', 'category')"
Use the Write tool to create this file at:
{backend}/api/schemas/{resource}.py
Replace all {Resource} with PascalCase and {resource} with snake_case.
src/backend/api/schemas/{resource}.py"""
Pydantic schemas for {Resource}.
CRITICAL: All schemas MUST inherit from CamelModel, NOT BaseModel.
This ensures camelCase JSON keys for frontend compatibility.
"""
from datetime import datetime
from typing import List, Optional
from pydantic import Field, ConfigDict
from api.schemas._base import CamelModel
class {Resource}Base(CamelModel):
"""Base schema with shared fields."""
name_en: str = Field(..., min_length=1, max_length=128)
name_ar: Optional[str] = Field(None, max_length=128)
description_en: Optional[str] = Field(None, max_length=512)
description_ar: Optional[str] = Field(None, max_length=512)
is_active: bool = True
model_config = ConfigDict(from_attributes=True)
class {Resource}Create({Resource}Base):
"""Schema for creating a new {resource}.
Used in POST requests.
"""
pass
class {Resource}Update(CamelModel):
"""Schema for updating a {resource}.
All fields optional for partial updates.
Used in PUT/PATCH requests.
"""
name_en: Optional[str] = Field(None, min_length=1, max_length=128)
name_ar: Optional[str] = Field(None, max_length=128)
description_en: Optional[str] = Field(None, max_length=512)
description_ar: Optional[str] = Field(None, max_length=512)
is_active: Optional[bool] = None
model_config = ConfigDict(from_attributes=True)
class {Resource}Response({Resource}Base):
"""Schema for {resource} responses.
Includes all fields plus server-generated ones.
Used in GET responses.
"""
id: str
created_at: datetime
updated_at: Optional[datetime] = None
model_config = ConfigDict(from_attributes=True)
class {Resource}ListResponse(CamelModel):
"""Schema for paginated list responses."""
items: List[{Resource}Response]
total: int
page: int
per_page: int
total_pages: int
model_config = ConfigDict(from_attributes=True)
CamelModel (from api.schemas._base)snake_case for Python field names (auto-converted to camelCase in JSON)model_config = ConfigDict(from_attributes=True) for ORM compatibilityField() for validation constraints_en and _ar suffixesBaseModel directlyalias_generator manuallyField(alias="camelCase") for camelCase conversionGiven this schema:
class UserResponse(CamelModel):
user_id: str
full_name: str
is_active: bool
created_at: datetime
The JSON output will be:
{
"userId": "abc123",
"fullName": "John Doe",
"isActive": true,
"createdAt": "2024-01-15T10:30:00Z"
}
The conversion happens automatically via CamelModel's alias_generator.
After creating the file, output:
✅ Schemas created: {backend}/api/schemas/{resource}.py
Created schemas:
- {Resource}Base - Shared fields
- {Resource}Create - For POST requests
- {Resource}Update - For PUT/PATCH requests
- {Resource}Response - For GET responses
- {Resource}ListResponse - For paginated lists
Next steps:
1. Create repository: /fastapi-patterns:scaffold-repository {resource}
2. Create service: /fastapi-patterns:scaffold-service {resource}
3. Create router: /fastapi-patterns:scaffold-router {resource}
This command MUST:
DO NOT just show the template. ACTUALLY CREATE THE FILE.