"""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})" ) )