drf-to-mkdoc 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of drf-to-mkdoc might be problematic. Click here for more details.
- drf_to_mkdoc-0.1.0/LICENSE +21 -0
- drf_to_mkdoc-0.1.0/MANIFEST.in +18 -0
- drf_to_mkdoc-0.1.0/PKG-INFO +247 -0
- drf_to_mkdoc-0.1.0/README.md +198 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/__init__.py +7 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/apps.py +15 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/conf/__init__.py +0 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/conf/defaults.py +11 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/conf/settings.py +44 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/__init__.py +0 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/commands/__init__.py +0 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/commands/build_docs.py +76 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/commands/generate_doc_json.py +512 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/commands/generate_docs.py +138 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/commands/generate_model_docs.py +327 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/management/commands/update_doc_schema.py +53 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/__init__.py +3 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/common.py +292 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/endpoint_generator.py +945 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/extractors/__init__.py +3 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/extractors/query_parameter_extractors.py +229 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/md_generators/__init__.py +0 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/md_generators/query_parameters_generators.py +72 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc/utils/model_generator.py +269 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc.egg-info/PKG-INFO +247 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc.egg-info/SOURCES.txt +29 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc.egg-info/dependency_links.txt +1 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc.egg-info/requires.txt +15 -0
- drf_to_mkdoc-0.1.0/drf_to_mkdoc.egg-info/top_level.txt +1 -0
- drf_to_mkdoc-0.1.0/pyproject.toml +75 -0
- drf_to_mkdoc-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ShayestehHs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21
|
+
IN THE SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include MANIFEST.in
|
|
4
|
+
include pyproject.toml
|
|
5
|
+
|
|
6
|
+
recursive-include drf_to_mkdoc/conf *.py
|
|
7
|
+
recursive-include drf_to_mkdoc/utils *.py
|
|
8
|
+
recursive-include drf_to_mkdoc/management *.py
|
|
9
|
+
|
|
10
|
+
global-exclude *.pyc
|
|
11
|
+
global-exclude *.pyo
|
|
12
|
+
global-exclude __pycache__
|
|
13
|
+
global-exclude .DS_Store
|
|
14
|
+
global-exclude .git*
|
|
15
|
+
global-exclude .idea
|
|
16
|
+
global-exclude .venv
|
|
17
|
+
global-exclude .env
|
|
18
|
+
global-exclude *.log
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: drf-to-mkdoc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Generate Markdown API docs from Django/DRF OpenAPI schema for MkDocs
|
|
5
|
+
Author-email: Your Name <your@email.com>
|
|
6
|
+
Maintainer-email: Your Name <your@email.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/yourusername/drf-to-mkdoc
|
|
9
|
+
Project-URL: Repository, https://github.com/yourusername/drf-to-mkdoc
|
|
10
|
+
Project-URL: Documentation, https://github.com/yourusername/drf-to-mkdoc#readme
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/yourusername/drf-to-mkdoc/issues
|
|
12
|
+
Keywords: django,django-rest-framework,documentation,mkdocs,api
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Framework :: Django
|
|
24
|
+
Classifier: Framework :: Django :: 3.2
|
|
25
|
+
Classifier: Framework :: Django :: 4.0
|
|
26
|
+
Classifier: Framework :: Django :: 4.1
|
|
27
|
+
Classifier: Framework :: Django :: 4.2
|
|
28
|
+
Classifier: Framework :: Django :: 5.0
|
|
29
|
+
Classifier: Topic :: Documentation
|
|
30
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
31
|
+
Requires-Python: >=3.8
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: Django<6.0,>=3.2
|
|
35
|
+
Requires-Dist: djangorestframework<4.0,>=3.12
|
|
36
|
+
Requires-Dist: PyYAML>=6.0
|
|
37
|
+
Requires-Dist: drf-spectacular>=0.26.0
|
|
38
|
+
Requires-Dist: mkdocs>=1.4.0
|
|
39
|
+
Requires-Dist: mkdocs-material>=9.0.0
|
|
40
|
+
Requires-Dist: coreapi>=2.3.0
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-django>=4.5.0; extra == "dev"
|
|
44
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: isort>=5.10.0; extra == "dev"
|
|
46
|
+
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# DRF to MkDocs
|
|
51
|
+
|
|
52
|
+
Generate beautiful, interactive Markdown API documentation from Django REST Framework OpenAPI schema for MkDocs.
|
|
53
|
+
|
|
54
|
+
## Why you'll love it
|
|
55
|
+
|
|
56
|
+
- **Zero-hassle docs**: Beautiful, always-in-sync API docs straight from your codebase
|
|
57
|
+
- **Model deep dive**: Auto-generated model pages with fields, relationships, and choices
|
|
58
|
+
- **Lightning-fast discovery**: Interactive endpoint index with powerful filters and search
|
|
59
|
+
- **DRF-native**: Works with DRF Spectacular; no custom schema wiring needed
|
|
60
|
+
- **MkDocs Material**: Looks great out of the box with the Material theme
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
See the full installation guide in `docs/installation.md`.
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
1. **Configure your Django project**:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# settings.py
|
|
72
|
+
INSTALLED_APPS = [
|
|
73
|
+
# ... your other apps
|
|
74
|
+
'drf_to_mkdoc',
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
# Required for OpenAPI schema generation
|
|
78
|
+
REST_FRAMEWORK = {
|
|
79
|
+
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
SPECTACULAR_SETTINGS = {
|
|
83
|
+
'TITLE': 'Your API',
|
|
84
|
+
'DESCRIPTION': 'Your API description',
|
|
85
|
+
'VERSION': '1.0.0',
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
DRF_TO_MKDOC = {
|
|
89
|
+
'DJANGO_APPS': [
|
|
90
|
+
'users',
|
|
91
|
+
'products',
|
|
92
|
+
'orders',
|
|
93
|
+
'inventory',
|
|
94
|
+
],
|
|
95
|
+
# Optional: Override default paths
|
|
96
|
+
# 'DOCS_DIR': 'docs',
|
|
97
|
+
# 'CONFIG_DIR': 'docs/configs',
|
|
98
|
+
# 'MODEL_DOCS_FILE': 'docs/model-docs.json',
|
|
99
|
+
# 'DOC_CONFIG_FILE': 'docs/configs/doc_config.json',
|
|
100
|
+
# 'CUSTOM_SCHEMA_FILE': 'docs/configs/custom_schema.json',
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
2. **Create MkDocs configuration**:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
# mkdocs.yml
|
|
108
|
+
site_name: Your API Documentation
|
|
109
|
+
theme:
|
|
110
|
+
name: material
|
|
111
|
+
features:
|
|
112
|
+
- navigation.tabs
|
|
113
|
+
- navigation.sections
|
|
114
|
+
- navigation.expand
|
|
115
|
+
- search.highlight
|
|
116
|
+
- search.share
|
|
117
|
+
|
|
118
|
+
plugins:
|
|
119
|
+
- search
|
|
120
|
+
|
|
121
|
+
nav:
|
|
122
|
+
- Home: index.md
|
|
123
|
+
- About: about.md
|
|
124
|
+
- Models: models/index.md
|
|
125
|
+
- API Endpoints: endpoints/index.md
|
|
126
|
+
- Pagination: pagination.md
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
3. **Build documentation**:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
python manage.py build_docs --settings=docs_settings
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## What you get
|
|
136
|
+
|
|
137
|
+
See a detailed overview of generated files in `docs/structure.md` and a feature breakdown in `docs/features.md`.
|
|
138
|
+
|
|
139
|
+
## How it works
|
|
140
|
+
|
|
141
|
+
Under the hood, drf-to-mkdoc introspects your models and reads your DRF OpenAPI schema to generate clean, organized Markdown. Then MkDocs turns it into a polished static site. Always current, no manual updates.
|
|
142
|
+
|
|
143
|
+
## Explore more
|
|
144
|
+
|
|
145
|
+
- Customizing endpoint docs: `docs/customizing_endpoints.md`
|
|
146
|
+
- Serving docs through Django (with permissions): `docs/serving_mkdocs_with_django.md`
|
|
147
|
+
|
|
148
|
+
## Dependencies
|
|
149
|
+
|
|
150
|
+
- Django >= 3.2, < 6.0
|
|
151
|
+
- Django REST Framework >= 3.12, < 4.0
|
|
152
|
+
- drf-spectacular >= 0.26.0
|
|
153
|
+
- PyYAML >= 6.0
|
|
154
|
+
- MkDocs >= 1.4.0
|
|
155
|
+
- MkDocs Material >= 9.0.0
|
|
156
|
+
- coreapi >= 2.3.0
|
|
157
|
+
|
|
158
|
+
## Development
|
|
159
|
+
|
|
160
|
+
### Setup Development Environment
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
git clone https://github.com/yourusername/drf-to-mkdoc.git
|
|
164
|
+
cd drf-to-mkdoc
|
|
165
|
+
pip install -e ".[dev]"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Project Structure
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
drf-to-mkdoc/
|
|
172
|
+
├── drf_to_mkdoc/
|
|
173
|
+
│ ├── conf/
|
|
174
|
+
│ │ ├── defaults.py # Default configuration values
|
|
175
|
+
│ │ └── settings.py # Settings management
|
|
176
|
+
│ ├── management/
|
|
177
|
+
│ │ └── commands/
|
|
178
|
+
│ │ ├── build_docs.py # Build MkDocs site
|
|
179
|
+
│ │ ├── generate_docs.py # Main documentation generator
|
|
180
|
+
│ │ ├── generate_model_docs.py # Model documentation
|
|
181
|
+
│ │ └── update_doc_schema.py # Schema updates
|
|
182
|
+
│ └── utils/
|
|
183
|
+
│ ├── common.py # Shared utilities
|
|
184
|
+
│ ├── endpoint_generator.py # Endpoint documentation
|
|
185
|
+
│ ├── model_generator.py # Model documentation
|
|
186
|
+
│ └── extractors/ # Query parameter extraction
|
|
187
|
+
├── pyproject.toml # Project configuration
|
|
188
|
+
└── README.md
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
194
|
+
|
|
195
|
+
## Recommendations
|
|
196
|
+
|
|
197
|
+
### .gitignore Configuration
|
|
198
|
+
|
|
199
|
+
To avoid committing generated files to your repository, add the following to your `.gitignore` file:
|
|
200
|
+
|
|
201
|
+
```gitignore
|
|
202
|
+
# Documentation
|
|
203
|
+
/docs/endpoints/
|
|
204
|
+
/docs/models/
|
|
205
|
+
/docs/configs/doc-schema.yaml
|
|
206
|
+
|
|
207
|
+
# Build artifacts
|
|
208
|
+
/site/
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
This will ensure that only the source configuration and scripts are versioned, while the generated documentation is excluded.
|
|
212
|
+
|
|
213
|
+
### docs_settings.py Best Practices
|
|
214
|
+
|
|
215
|
+
Create a separate `docs_settings.py` file that inherits from your main settings:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
# docs_settings.py
|
|
219
|
+
from .settings import *
|
|
220
|
+
|
|
221
|
+
DRF_TO_MKDOC = {
|
|
222
|
+
'DJANGO_APPS': ['your_app1', 'your_app2'],
|
|
223
|
+
}
|
|
224
|
+
# Other doc settings...
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Then use the `--settings` argument when running the build command:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
python manage.py build_docs --settings=docs_settings
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Project Organization
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
your-project/
|
|
237
|
+
├── settings.py # Main Django settings
|
|
238
|
+
├── docs_settings.py # Documentation-specific settings
|
|
239
|
+
├── mkdocs.yml # MkDocs configuration
|
|
240
|
+
├── docs/ # Generated documentation (gitignored)
|
|
241
|
+
└── site/ # Built site (gitignored)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Contributing
|
|
245
|
+
|
|
246
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed contribution guidelines.
|
|
247
|
+
This will ensure that only the source configuration and scripts are versioned, while the generated documentation is excluded.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# DRF to MkDocs
|
|
2
|
+
|
|
3
|
+
Generate beautiful, interactive Markdown API documentation from Django REST Framework OpenAPI schema for MkDocs.
|
|
4
|
+
|
|
5
|
+
## Why you'll love it
|
|
6
|
+
|
|
7
|
+
- **Zero-hassle docs**: Beautiful, always-in-sync API docs straight from your codebase
|
|
8
|
+
- **Model deep dive**: Auto-generated model pages with fields, relationships, and choices
|
|
9
|
+
- **Lightning-fast discovery**: Interactive endpoint index with powerful filters and search
|
|
10
|
+
- **DRF-native**: Works with DRF Spectacular; no custom schema wiring needed
|
|
11
|
+
- **MkDocs Material**: Looks great out of the box with the Material theme
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
See the full installation guide in `docs/installation.md`.
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
1. **Configure your Django project**:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
# settings.py
|
|
23
|
+
INSTALLED_APPS = [
|
|
24
|
+
# ... your other apps
|
|
25
|
+
'drf_to_mkdoc',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
# Required for OpenAPI schema generation
|
|
29
|
+
REST_FRAMEWORK = {
|
|
30
|
+
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
SPECTACULAR_SETTINGS = {
|
|
34
|
+
'TITLE': 'Your API',
|
|
35
|
+
'DESCRIPTION': 'Your API description',
|
|
36
|
+
'VERSION': '1.0.0',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
DRF_TO_MKDOC = {
|
|
40
|
+
'DJANGO_APPS': [
|
|
41
|
+
'users',
|
|
42
|
+
'products',
|
|
43
|
+
'orders',
|
|
44
|
+
'inventory',
|
|
45
|
+
],
|
|
46
|
+
# Optional: Override default paths
|
|
47
|
+
# 'DOCS_DIR': 'docs',
|
|
48
|
+
# 'CONFIG_DIR': 'docs/configs',
|
|
49
|
+
# 'MODEL_DOCS_FILE': 'docs/model-docs.json',
|
|
50
|
+
# 'DOC_CONFIG_FILE': 'docs/configs/doc_config.json',
|
|
51
|
+
# 'CUSTOM_SCHEMA_FILE': 'docs/configs/custom_schema.json',
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. **Create MkDocs configuration**:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
# mkdocs.yml
|
|
59
|
+
site_name: Your API Documentation
|
|
60
|
+
theme:
|
|
61
|
+
name: material
|
|
62
|
+
features:
|
|
63
|
+
- navigation.tabs
|
|
64
|
+
- navigation.sections
|
|
65
|
+
- navigation.expand
|
|
66
|
+
- search.highlight
|
|
67
|
+
- search.share
|
|
68
|
+
|
|
69
|
+
plugins:
|
|
70
|
+
- search
|
|
71
|
+
|
|
72
|
+
nav:
|
|
73
|
+
- Home: index.md
|
|
74
|
+
- About: about.md
|
|
75
|
+
- Models: models/index.md
|
|
76
|
+
- API Endpoints: endpoints/index.md
|
|
77
|
+
- Pagination: pagination.md
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
3. **Build documentation**:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python manage.py build_docs --settings=docs_settings
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## What you get
|
|
87
|
+
|
|
88
|
+
See a detailed overview of generated files in `docs/structure.md` and a feature breakdown in `docs/features.md`.
|
|
89
|
+
|
|
90
|
+
## How it works
|
|
91
|
+
|
|
92
|
+
Under the hood, drf-to-mkdoc introspects your models and reads your DRF OpenAPI schema to generate clean, organized Markdown. Then MkDocs turns it into a polished static site. Always current, no manual updates.
|
|
93
|
+
|
|
94
|
+
## Explore more
|
|
95
|
+
|
|
96
|
+
- Customizing endpoint docs: `docs/customizing_endpoints.md`
|
|
97
|
+
- Serving docs through Django (with permissions): `docs/serving_mkdocs_with_django.md`
|
|
98
|
+
|
|
99
|
+
## Dependencies
|
|
100
|
+
|
|
101
|
+
- Django >= 3.2, < 6.0
|
|
102
|
+
- Django REST Framework >= 3.12, < 4.0
|
|
103
|
+
- drf-spectacular >= 0.26.0
|
|
104
|
+
- PyYAML >= 6.0
|
|
105
|
+
- MkDocs >= 1.4.0
|
|
106
|
+
- MkDocs Material >= 9.0.0
|
|
107
|
+
- coreapi >= 2.3.0
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
### Setup Development Environment
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
git clone https://github.com/yourusername/drf-to-mkdoc.git
|
|
115
|
+
cd drf-to-mkdoc
|
|
116
|
+
pip install -e ".[dev]"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Project Structure
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
drf-to-mkdoc/
|
|
123
|
+
├── drf_to_mkdoc/
|
|
124
|
+
│ ├── conf/
|
|
125
|
+
│ │ ├── defaults.py # Default configuration values
|
|
126
|
+
│ │ └── settings.py # Settings management
|
|
127
|
+
│ ├── management/
|
|
128
|
+
│ │ └── commands/
|
|
129
|
+
│ │ ├── build_docs.py # Build MkDocs site
|
|
130
|
+
│ │ ├── generate_docs.py # Main documentation generator
|
|
131
|
+
│ │ ├── generate_model_docs.py # Model documentation
|
|
132
|
+
│ │ └── update_doc_schema.py # Schema updates
|
|
133
|
+
│ └── utils/
|
|
134
|
+
│ ├── common.py # Shared utilities
|
|
135
|
+
│ ├── endpoint_generator.py # Endpoint documentation
|
|
136
|
+
│ ├── model_generator.py # Model documentation
|
|
137
|
+
│ └── extractors/ # Query parameter extraction
|
|
138
|
+
├── pyproject.toml # Project configuration
|
|
139
|
+
└── README.md
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
145
|
+
|
|
146
|
+
## Recommendations
|
|
147
|
+
|
|
148
|
+
### .gitignore Configuration
|
|
149
|
+
|
|
150
|
+
To avoid committing generated files to your repository, add the following to your `.gitignore` file:
|
|
151
|
+
|
|
152
|
+
```gitignore
|
|
153
|
+
# Documentation
|
|
154
|
+
/docs/endpoints/
|
|
155
|
+
/docs/models/
|
|
156
|
+
/docs/configs/doc-schema.yaml
|
|
157
|
+
|
|
158
|
+
# Build artifacts
|
|
159
|
+
/site/
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
This will ensure that only the source configuration and scripts are versioned, while the generated documentation is excluded.
|
|
163
|
+
|
|
164
|
+
### docs_settings.py Best Practices
|
|
165
|
+
|
|
166
|
+
Create a separate `docs_settings.py` file that inherits from your main settings:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
# docs_settings.py
|
|
170
|
+
from .settings import *
|
|
171
|
+
|
|
172
|
+
DRF_TO_MKDOC = {
|
|
173
|
+
'DJANGO_APPS': ['your_app1', 'your_app2'],
|
|
174
|
+
}
|
|
175
|
+
# Other doc settings...
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Then use the `--settings` argument when running the build command:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
python manage.py build_docs --settings=docs_settings
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Project Organization
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
your-project/
|
|
188
|
+
├── settings.py # Main Django settings
|
|
189
|
+
├── docs_settings.py # Documentation-specific settings
|
|
190
|
+
├── mkdocs.yml # MkDocs configuration
|
|
191
|
+
├── docs/ # Generated documentation (gitignored)
|
|
192
|
+
└── site/ # Built site (gitignored)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Contributing
|
|
196
|
+
|
|
197
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed contribution guidelines.
|
|
198
|
+
This will ensure that only the source configuration and scripts are versioned, while the generated documentation is excluded.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from django.apps import AppConfig
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DrfToMkdocConfig(AppConfig):
|
|
5
|
+
default_auto_field = "django.db.models.BigAutoField"
|
|
6
|
+
name = "drf_to_mkdoc"
|
|
7
|
+
verbose_name = "DRF to MkDocs Documentation Generator"
|
|
8
|
+
|
|
9
|
+
def ready(self):
|
|
10
|
+
"""Initialize the app when Django starts."""
|
|
11
|
+
# Import management commands to register them
|
|
12
|
+
try:
|
|
13
|
+
import drf_to_mkdoc.management.commands # noqa
|
|
14
|
+
except ImportError:
|
|
15
|
+
pass
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
DEFAULTS = {
|
|
2
|
+
# Path configurations with defaults
|
|
3
|
+
"DOCS_DIR": "docs", # Directory where docs will be generated
|
|
4
|
+
"CONFIG_DIR": "docs/configs", # Directory for configuration files
|
|
5
|
+
"MODEL_DOCS_FILE": "docs/model-docs.json", # Path to model documentation JSON file
|
|
6
|
+
"DOC_CONFIG_FILE": "docs/configs/doc_config.json", # Path to documentation configuration file
|
|
7
|
+
"CUSTOM_SCHEMA_FILE": "docs/configs/custom_schema.json", # Path to custom schema file
|
|
8
|
+
|
|
9
|
+
# Django apps - required, no default
|
|
10
|
+
"DJANGO_APPS": None, # List of Django app names to process
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
from drf_to_mkdoc.conf.defaults import DEFAULTS
|
|
3
|
+
|
|
4
|
+
class DRFToMkDocSettings:
|
|
5
|
+
required_settings = ["DJANGO_APPS"]
|
|
6
|
+
|
|
7
|
+
def __init__(self, user_settings_key="DRF_TO_MKDOC", defaults=None):
|
|
8
|
+
self.user_settings_key = user_settings_key
|
|
9
|
+
self._user_settings = getattr(settings, user_settings_key, {})
|
|
10
|
+
self.defaults = defaults or {}
|
|
11
|
+
|
|
12
|
+
def get(self, key):
|
|
13
|
+
if key not in self.defaults:
|
|
14
|
+
raise AttributeError(f"Invalid DRF_TO_MKDOC setting: '{key}'")
|
|
15
|
+
|
|
16
|
+
value = self._user_settings.get(key, self.defaults[key])
|
|
17
|
+
|
|
18
|
+
if value is None and key in self.required_settings:
|
|
19
|
+
raise ValueError(
|
|
20
|
+
f"DRF_TO_MKDOC setting '{key}' is required but not configured. "
|
|
21
|
+
f"Please add it to your Django settings under {self.user_settings_key}."
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return value
|
|
25
|
+
|
|
26
|
+
def __getattr__(self, key):
|
|
27
|
+
return self.get(key)
|
|
28
|
+
|
|
29
|
+
def validate_required_settings(self):
|
|
30
|
+
missing_settings = []
|
|
31
|
+
|
|
32
|
+
for setting in self.required_settings:
|
|
33
|
+
try:
|
|
34
|
+
self.get(setting)
|
|
35
|
+
except ValueError:
|
|
36
|
+
missing_settings.append(setting)
|
|
37
|
+
|
|
38
|
+
if missing_settings:
|
|
39
|
+
raise ValueError(
|
|
40
|
+
f"Missing required settings: {', '.join(missing_settings)}. "
|
|
41
|
+
f"Please configure these in your Django settings under {self.user_settings_key}."
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
drf_to_mkdoc_settings = DRFToMkDocSettings(defaults=DEFAULTS)
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from django.conf import settings
|
|
5
|
+
from django.core.management.base import BaseCommand, CommandError
|
|
6
|
+
from django.apps import apps
|
|
7
|
+
from drf_to_mkdoc.conf.settings import drf_to_mkdoc_settings
|
|
8
|
+
from django.core.management import call_command
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Command(BaseCommand):
|
|
12
|
+
help = "Build MkDocs documentation"
|
|
13
|
+
|
|
14
|
+
def handle(self, *args, **options):
|
|
15
|
+
drf_to_mkdoc_settings.validate_required_settings()
|
|
16
|
+
self.stdout.write(self.style.SUCCESS("✅ DRF_TO_MKDOC settings validated."))
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
apps.check_apps_ready()
|
|
20
|
+
except Exception as e:
|
|
21
|
+
raise CommandError(f"Django apps not properly configured: {e}")
|
|
22
|
+
|
|
23
|
+
base_dir = Path(settings.BASE_DIR)
|
|
24
|
+
site_dir = base_dir / "site"
|
|
25
|
+
mkdocs_config = base_dir / "mkdocs.yml"
|
|
26
|
+
mkdocs_config_alt = base_dir / "mkdocs.yaml"
|
|
27
|
+
|
|
28
|
+
if not mkdocs_config.exists() and not mkdocs_config_alt.exists():
|
|
29
|
+
raise CommandError(
|
|
30
|
+
"MkDocs configuration file not found. Please create either 'mkdocs.yml' or 'mkdocs.yaml' "
|
|
31
|
+
"in your project root directory."
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
# Generate the model documentation JSON first
|
|
36
|
+
self.stdout.write("Generating model documentation...")
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
call_command(
|
|
40
|
+
"generate_model_docs", "--pretty"
|
|
41
|
+
)
|
|
42
|
+
self.stdout.write(self.style.SUCCESS("Model documentation generated."))
|
|
43
|
+
except Exception as e:
|
|
44
|
+
self.stdout.write(self.style.WARNING(f"Failed to generate model docs: {e}"))
|
|
45
|
+
|
|
46
|
+
# Generate the documentation content
|
|
47
|
+
self.stdout.write("Generating documentation content...")
|
|
48
|
+
try:
|
|
49
|
+
call_command("generate_docs")
|
|
50
|
+
self.stdout.write(self.style.SUCCESS("Documentation content generated."))
|
|
51
|
+
except Exception as e:
|
|
52
|
+
self.stdout.write(self.style.ERROR(f"Failed to generate docs: {e}"))
|
|
53
|
+
raise
|
|
54
|
+
|
|
55
|
+
# Build the MkDocs site
|
|
56
|
+
self.stdout.write("Building MkDocs site...")
|
|
57
|
+
result = subprocess.run(
|
|
58
|
+
["mkdocs", "build", "--clean"],
|
|
59
|
+
check=False,
|
|
60
|
+
cwd=base_dir,
|
|
61
|
+
capture_output=True,
|
|
62
|
+
text=True,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if result.returncode != 0:
|
|
66
|
+
raise CommandError(f"MkDocs build failed: {result.stderr}")
|
|
67
|
+
|
|
68
|
+
self.stdout.write(self.style.SUCCESS("Documentation built successfully!"))
|
|
69
|
+
self.stdout.write(f"Site built in: {site_dir}")
|
|
70
|
+
|
|
71
|
+
except FileNotFoundError as e:
|
|
72
|
+
raise CommandError(
|
|
73
|
+
"MkDocs not found. Please install it with: pip install mkdocs mkdocs-material"
|
|
74
|
+
) from e
|
|
75
|
+
except Exception as e:
|
|
76
|
+
raise CommandError(f"Error building documentation: {e!s}") from e
|