API Reference Generation
This directory contains tools to automatically generate API reference documentation from the Django codebase.
Quick Start
Generate API Reference Documentation
# From the docs directory
./generate_refs.sh
# Or directly with Python
python generate_api_refs.py
What Gets Generated
The script automatically analyzes your Django apps and generates:
- Models: Field definitions, types, constraints, and methods
- Views: Class-based and function-based views with HTTP methods
- Forms: Form fields, validation rules, and help text
- App Overview: Complete documentation for each Django app
Files
generate_api_refs.py- Main Python script for generating documentationgenerate_refs.sh- Shell script wrapper for easy executionapi/- Directory containing generated API reference filesapi/index.md- Main index page linking to all app documentation
How It Works
- App Discovery: Scans
INSTALLED_APPSin Django settings - Code Analysis: Uses Python introspection to analyze models, views, and forms
- Documentation Generation: Creates markdown files with structured documentation
- Integration: Automatically integrates with MkDocs navigation
Customization
Adding New App Types
To document additional Django components, modify the script:
def analyze_admin(app_name: str, module: Any) -> Dict[str, Any]:
"""Analyze Django admin configurations."""
# Add your custom analysis logic here
pass
Customizing Output Format
Modify the generate_markdown() function to change the documentation structure and styling.
Integration with CI/CD
The API reference generation is automatically integrated with the GitHub Actions workflow:
- On Commit: Documentation is automatically generated
- On Push to Main: Documentation is deployed to GitHub Pages
- Always Up-to-Date: API docs stay synchronized with code changes
Requirements
- Python 3.13+
- Django 5.2.5+
- Access to Django settings and models
Troubleshooting
Common Issues
- Import Errors: Ensure Django is properly configured and apps are accessible
- Permission Errors: Make sure the shell script is executable (
chmod +x generate_refs.sh) - Missing Dependencies: Install required packages from
requirements.txt
Debug Mode
Add debug output to the script:
import logging
logging.basicConfig(level=logging.DEBUG)
Contributing
When adding new Django apps or components:
- Add proper docstrings to your models, views, and forms
- Test the documentation generation locally
- Ensure the generated docs are clear and accurate