Files
homm/backend/apps/common/management/commands/export_api_docs.py
T
apuc 3b3e5c429a Serve an offline API reference at /api/docs/
The Swagger UI page was blank on networks where the jsdelivr CDN is
unreachable (here the proxy answers 407), so /api/docs/ now returns a
server-rendered reference built from the same OpenAPI schema: inline
CSS/JS, no external requests, search across methods.

- Extract the renderer into apps/common/api_docs.py
- Add api_docs_view and route it to /api/docs/
- Move Swagger UI to /api/swagger/, keep ReDoc at /api/redoc/
- Let export_api_docs reuse the shared renderer (new search field)
- Update the docs entry points in docs/architecture.md
2026-11-22 22:09:41 +03:00

39 lines
1.3 KiB
Python

"""Exports the OpenAPI schema into a standalone HTML reference.
The rendering lives in :mod:`apps.common.api_docs` and is shared with the
``/api/docs/`` page, so the file and the served page always look the same.
"""
from pathlib import Path
from django.core.management.base import BaseCommand
from apps.common.api_docs import build_schema, render_api_docs_html
class Command(BaseCommand):
help = (
"Рендерит OpenAPI-схему в один автономный HTML-файл "
"(без CDN и внешних запросов)."
)
def add_arguments(self, parser):
parser.add_argument(
"--out",
default="api-reference.html",
help="Куда сохранить HTML (по умолчанию backend/api-reference.html).",
)
def handle(self, *args, **options):
schema = build_schema()
document = render_api_docs_html(schema)
operations = sum(len(methods) for methods in schema.get("paths", {}).values())
out_path = Path(options["out"])
out_path.write_text(document, encoding="utf-8")
self.stdout.write(
self.style.SUCCESS(
f"Готово: {out_path} ({len(document)} байт, операций: {operations})"
)
)