We need to integrate and configure Swagger (OpenAPI) documentation for the Django REST API to improve developer experience, ensure clear API visibility, and simplify frontend/backend collaboration.
Requirements
Swagger Integration
Technical Details
- Add Swagger/Redoc dependencies to
requirements.txt.
- Update project URLs (e.g.,
urls.py) to include schema and UI routes.
- Configure Swagger metadata:
- API title, version, description
- Contact and license info (optional)
- If authentication is used (e.g., JWT or TokenAuth):
- Display authorization header in the Swagger UI (
Bearer <token>)
- Allow interactive testing of secured endpoints
- Ensure the documentation is only accessible in development or staging environments by default.
Recommendations (for uncertain points)
- Library choice: Prefer
drf-spectacular for better OpenAPI 3 support and long-term maintenance.
- Access control: Add environment-based toggle (e.g., via
DEBUG flag) to disable Swagger in production.
- Schema customization: If project uses custom permissions or viewsets, annotate them with
@extend_schema decorators for clarity.
- Versioning: Include API version in the schema title (e.g., “Game API v1”).
Testing
Definition of Done
We need to integrate and configure Swagger (OpenAPI) documentation for the Django REST API to improve developer experience, ensure clear API visibility, and simplify frontend/backend collaboration.
Requirements
Swagger Integration
drf-yasg— classic and stable.drf-spectacular— modern, OpenAPI 3 compatible, preferred for new projects./api/docs/→ Swagger UI/api/redoc/→ Redoc UI/api/schema/→ raw OpenAPI JSON schemaTechnical Details
requirements.txt.urls.py) to include schema and UI routes.Bearer <token>)Recommendations (for uncertain points)
drf-spectacularfor better OpenAPI 3 support and long-term maintenance.DEBUGflag) to disable Swagger in production.@extend_schemadecorators for clarity.Testing
/api/docs/and/api/redoc/endpoints load correctly.Definition of Done