Performance: Example data in schema
MEDIUM IMPACT
This affects the speed of API response serialization and validation during request handling.
from pydantic import BaseModel class User(BaseModel): id: int name: str bio: str = "Short bio" class Config: schema_extra = { "example": { "id": 1, "name": "Alice", "bio": "Short bio" } }
from pydantic import BaseModel class User(BaseModel): id: int name: str bio: str = """A very long biography text repeated many times to simulate large example data...""" class Config: schema_extra = { "example": { "id": 1, "name": "Alice", "bio": "A very long biography text repeated many times to simulate large example data..." } }
| Pattern | Schema Size | Validation Time | Serialization Time | Verdict |
|---|---|---|---|---|
| Large example data | Large (10+ KB) | High (blocks startup) | High (adds 20ms) | [X] Bad |
| Minimal example data | Small (<1 KB) | Low (fast startup) | Low (adds <5ms) | [OK] Good |