| name | litestar-dto-openapi |
| description | Auto-activate for MsgspecDTO, DTOConfig, litestar.dto, OpenAPIConfig, response DTOs, schema_extra, RequestEncodingType, or /schema. Not for persistence models alone. |
Litestar DTO and OpenAPI
Use this skill for DTO selection, msgspec-first schemas, request/response typing, and OpenAPI shape.
Code Style Rules
- Prefer msgspec DTOs in Litestar apps unless the project is already Pydantic-led.
- Keep persistence models separate from API DTOs.
- Use camelCase wire names while Python stays snake_case.
- Exclude server-owned fields from write DTOs.
- Treat nullability and requiredness separately:
T | None permits null;
only a default value makes a field optional.
Quick Reference
Workflow
- Identify input, output, and persistence shapes separately.
- Choose msgspec DTOs or match the existing Pydantic stack.
- Configure excludes, partial updates, rename behavior, and media type.
- Check the generated OpenAPI schema.
Guardrails
- Do not leak internal persistence-only fields into write DTOs.
- Do not switch an existing Pydantic-heavy project to msgspec opportunistically.
- Do not rely on untyped dict payloads when request shape is known.
- Do not treat OpenAPI as documentation only; it is the contract.
Validation Checkpoint
Example
from litestar.dto import DTOConfig, MsgspecDTO
class UserWriteDTO(MsgspecDTO[UserWrite]):
config = DTOConfig(exclude={"id", "created_at"})
References Index
Official References
Shared Styleguide Baseline