drf-to-mkdoc 0.1.0__py3-none-any.whl → 0.1.3__py3-none-any.whl
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/__init__.py +6 -6
- drf_to_mkdoc/apps.py +14 -14
- drf_to_mkdoc/conf/settings.py +44 -44
- drf_to_mkdoc/management/commands/build_docs.py +76 -76
- drf_to_mkdoc/management/commands/generate_doc_json.py +512 -512
- drf_to_mkdoc/management/commands/generate_docs.py +138 -138
- drf_to_mkdoc/management/commands/generate_model_docs.py +327 -327
- drf_to_mkdoc/management/commands/update_doc_schema.py +53 -53
- drf_to_mkdoc/utils/__init__.py +3 -3
- drf_to_mkdoc/utils/endpoint_generator.py +945 -945
- drf_to_mkdoc/utils/extractors/__init__.py +3 -3
- drf_to_mkdoc/utils/extractors/query_parameter_extractors.py +229 -229
- drf_to_mkdoc/utils/md_generators/query_parameters_generators.py +72 -72
- drf_to_mkdoc/utils/model_generator.py +269 -269
- {drf_to_mkdoc-0.1.0.dist-info → drf_to_mkdoc-0.1.3.dist-info}/METADATA +247 -247
- drf_to_mkdoc-0.1.3.dist-info/RECORD +25 -0
- {drf_to_mkdoc-0.1.0.dist-info → drf_to_mkdoc-0.1.3.dist-info}/licenses/LICENSE +21 -21
- drf_to_mkdoc-0.1.0.dist-info/RECORD +0 -25
- {drf_to_mkdoc-0.1.0.dist-info → drf_to_mkdoc-0.1.3.dist-info}/WHEEL +0 -0
- {drf_to_mkdoc-0.1.0.dist-info → drf_to_mkdoc-0.1.3.dist-info}/top_level.txt +0 -0
drf_to_mkdoc/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""
|
|
2
|
-
DRF to MkDocs - Generate Markdown API docs from Django/DRF OpenAPI schema for MkDocs
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
__version__ = "0.1.0"
|
|
6
|
-
__author__ = "ShayestehHs"
|
|
1
|
+
"""
|
|
2
|
+
DRF to MkDocs - Generate Markdown API docs from Django/DRF OpenAPI schema for MkDocs
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
__author__ = "ShayestehHs"
|
|
7
7
|
__email__ = "shayestehhs1@gmail.com"
|
drf_to_mkdoc/apps.py
CHANGED
|
@@ -1,15 +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:
|
|
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
15
|
pass
|
drf_to_mkdoc/conf/settings.py
CHANGED
|
@@ -1,44 +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)
|
|
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)
|
|
@@ -1,76 +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
|
|
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
|