drf-to-mkdoc 0.1.9__py3-none-any.whl → 0.2.0__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/management/commands/generate_docs.py +46 -71
- drf_to_mkdoc/management/commands/generate_model_docs.py +4 -5
- drf_to_mkdoc/static/drf-to-mkdoc/javascripts/try-out-sidebar.js +879 -0
- drf_to_mkdoc/static/drf-to-mkdoc/stylesheets/endpoints/try-out-sidebar.css +728 -0
- drf_to_mkdoc/utils/endpoint_detail_generator.py +9 -1
- drf_to_mkdoc/utils/model_detail_generator.py +23 -25
- {drf_to_mkdoc-0.1.9.dist-info → drf_to_mkdoc-0.2.0.dist-info}/METADATA +1 -1
- {drf_to_mkdoc-0.1.9.dist-info → drf_to_mkdoc-0.2.0.dist-info}/RECORD +11 -9
- {drf_to_mkdoc-0.1.9.dist-info → drf_to_mkdoc-0.2.0.dist-info}/WHEEL +0 -0
- {drf_to_mkdoc-0.1.9.dist-info → drf_to_mkdoc-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {drf_to_mkdoc-0.1.9.dist-info → drf_to_mkdoc-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
1
|
from pathlib import Path
|
|
4
2
|
|
|
5
3
|
from django.core.management.base import BaseCommand
|
|
@@ -33,100 +31,77 @@ class Command(BaseCommand):
|
|
|
33
31
|
def handle(self, *args, **options):
|
|
34
32
|
self.stdout.write(self.style.SUCCESS("🚀 Starting documentation generation..."))
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
generate_models = not options["endpoints_only"]
|
|
35
|
+
generate_endpoints = not options["models_only"]
|
|
36
|
+
if not generate_models and not generate_endpoints:
|
|
37
|
+
self.stdout.write(
|
|
38
|
+
self.style.ERROR(
|
|
39
|
+
"❌ No outputs selected: --models-only and --endpoints-only cannot be used together"
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
return
|
|
43
|
+
docs_dir = self._setup_docs_directory()
|
|
44
|
+
models_data = self._load_models_data() if generate_models else {}
|
|
45
|
+
schema_data = self._load_schema_data() if generate_endpoints else {}
|
|
46
|
+
|
|
47
|
+
if generate_models and models_data:
|
|
48
|
+
self._generate_models_documentation(models_data, docs_dir)
|
|
38
49
|
|
|
39
|
-
if
|
|
40
|
-
self.
|
|
41
|
-
elif options["endpoints_only"]:
|
|
42
|
-
self._generate_endpoints_only()
|
|
43
|
-
else:
|
|
44
|
-
self._generate_all()
|
|
50
|
+
if generate_endpoints and schema_data:
|
|
51
|
+
self._generate_endpoints_documentation(schema_data, docs_dir)
|
|
45
52
|
|
|
46
53
|
self.stdout.write(self.style.SUCCESS("✅ Documentation generation complete!"))
|
|
47
54
|
|
|
48
|
-
def
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
def _setup_docs_directory(self):
|
|
56
|
+
docs_dir = Path(drf_to_mkdoc_settings.DOCS_DIR)
|
|
57
|
+
docs_dir.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
return docs_dir
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
def _load_models_data(self):
|
|
53
61
|
json_data = load_model_json_data()
|
|
54
62
|
models_data = json_data.get("models", {}) if json_data else {}
|
|
55
63
|
|
|
56
64
|
if not models_data:
|
|
57
65
|
self.stdout.write(self.style.WARNING("⚠️ No model data found"))
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
docs_dir = Path(drf_to_mkdoc_settings.DOCS_DIR)
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
generate_model_docs(models_data, docs_dir)
|
|
64
|
-
create_models_index(models_data, docs_dir)
|
|
67
|
+
return models_data
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# Load schema
|
|
73
|
-
schema = get_schema()
|
|
69
|
+
def _load_schema_data(self):
|
|
70
|
+
try:
|
|
71
|
+
schema = get_schema()
|
|
72
|
+
except Exception as e:
|
|
73
|
+
self.stdout.write(self.style.ERROR(f"❌ Failed to load OpenAPI schema: {e}"))
|
|
74
|
+
return {}
|
|
74
75
|
if not schema:
|
|
75
76
|
self.stdout.write(self.style.ERROR("❌ Failed to load OpenAPI schema"))
|
|
76
|
-
return
|
|
77
|
+
return {}
|
|
77
78
|
|
|
78
79
|
paths = schema.get("paths", {})
|
|
79
80
|
components = schema.get("components", {})
|
|
80
81
|
|
|
81
82
|
self.stdout.write(f"📊 Loaded {len(paths)} API paths")
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
return {"paths": paths, "components": components}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
total_endpoints = generate_endpoint_files(endpoints_by_app, components)
|
|
88
|
-
create_endpoints_index(endpoints_by_app, docs_dir)
|
|
89
|
-
|
|
90
|
-
self.stdout.write(
|
|
91
|
-
self.style.SUCCESS(
|
|
92
|
-
f"✅ Generated {total_endpoints} endpoint files with Django view introspection"
|
|
93
|
-
)
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
def _generate_all(self):
|
|
97
|
-
"""Generate complete documentation"""
|
|
98
|
-
self.stdout.write("📚 Generating complete documentation...")
|
|
99
|
-
|
|
100
|
-
docs_dir = Path(drf_to_mkdoc_settings.DOCS_DIR)
|
|
101
|
-
|
|
102
|
-
# Load data
|
|
103
|
-
json_data = load_model_json_data()
|
|
104
|
-
models_data = json_data.get("models", {}) if json_data else {}
|
|
105
|
-
schema = get_schema()
|
|
106
|
-
|
|
107
|
-
if not schema:
|
|
108
|
-
self.stdout.write(self.style.ERROR("❌ Failed to load OpenAPI schema"))
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
paths = schema.get("paths", {})
|
|
112
|
-
components = schema.get("components", {})
|
|
113
|
-
|
|
114
|
-
self.stdout.write(f"📊 Loaded {len(paths)} API paths")
|
|
86
|
+
def _generate_models_documentation(self, models_data, docs_dir):
|
|
87
|
+
self.stdout.write("📋 Generating model documentation...")
|
|
115
88
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
self.stdout.write(self.style.WARNING(f"⚠️ Failed to generate model docs: {e}"))
|
|
89
|
+
try:
|
|
90
|
+
generate_model_docs(models_data)
|
|
91
|
+
create_models_index(models_data, docs_dir)
|
|
92
|
+
self.stdout.write(self.style.SUCCESS("✅ Model documentation generated"))
|
|
93
|
+
except Exception as e:
|
|
94
|
+
self.stdout.write(self.style.WARNING(f"⚠️ Failed to generate model docs: {e}"))
|
|
95
|
+
if hasattr(self, "_generating_all"):
|
|
124
96
|
self.stdout.write(self.style.WARNING("Continuing with endpoint generation..."))
|
|
125
|
-
|
|
126
|
-
self.stdout.write(self.style.WARNING("⚠️ No model data found"))
|
|
97
|
+
raise
|
|
127
98
|
|
|
128
|
-
|
|
99
|
+
def _generate_endpoints_documentation(self, schema_data, docs_dir):
|
|
129
100
|
self.stdout.write("🔗 Generating endpoint documentation...")
|
|
101
|
+
|
|
102
|
+
paths = schema_data["paths"]
|
|
103
|
+
components = schema_data["components"]
|
|
104
|
+
|
|
130
105
|
endpoints_by_app = parse_endpoints_from_schema(paths)
|
|
131
106
|
total_endpoints = generate_endpoint_files(endpoints_by_app, components)
|
|
132
107
|
create_endpoints_index(endpoints_by_app, docs_dir)
|
|
@@ -100,7 +100,7 @@ class Command(BaseCommand):
|
|
|
100
100
|
"description": self.get_model_description(model),
|
|
101
101
|
"abstract": meta.abstract,
|
|
102
102
|
"proxy": meta.proxy,
|
|
103
|
-
"
|
|
103
|
+
"column_fields": {},
|
|
104
104
|
"relationships": {},
|
|
105
105
|
"meta_options": self.get_meta_options(meta),
|
|
106
106
|
"methods": self.get_model_methods(model),
|
|
@@ -111,10 +111,9 @@ class Command(BaseCommand):
|
|
|
111
111
|
if field.many_to_many or field.one_to_many or field.many_to_one or field.one_to_one:
|
|
112
112
|
# Handle relationships separately
|
|
113
113
|
model_doc["relationships"][field.name] = self.introspect_relationship(field)
|
|
114
|
-
|
|
115
|
-
# Handle
|
|
116
|
-
model_doc["
|
|
117
|
-
|
|
114
|
+
if not (field.one_to_many or field.many_to_many):
|
|
115
|
+
# Handle column fields
|
|
116
|
+
model_doc["column_fields"][field.name] = self.introspect_field(field)
|
|
118
117
|
return model_doc
|
|
119
118
|
|
|
120
119
|
def introspect_field(self, field):
|