High Fastapi

Use Pydantic models for request/response

Rule Description

Define explicit Pydantic models for all API inputs and outputs:
- Automatic validation and documentation
- Type safety with IDE support
- Clear API contract

```python
from pydantic import BaseModel, Field

class UserCreate(BaseModel):
email: str = Field(..., description="User email address")
name: str = Field(..., min_length=1, max_length=100)

class UserResponse(BaseModel):
id: int
email: str
name: str
created_at: datetime

class Config:
from_attributes = True

@app.post("/users", response_model=UserResponse)
async def create_user(user: UserCreate) -> UserResponse:
...
```

Included in Rulesets

Django Best Practices
36 rules • 1 standard
View
FastAPI Guidelines
36 rules • 1 standard
View
Python Standards
33 rules • 2 standards
View
Code Review Standards
58 rules • 0 standards
View

Add This Rule

Sign in to add this rule to your workspace

Sign in with GitHub

Details

Severity
High
Category
Fastapi
Used in
4 rulesets