#!/usr/bin/env python3 """导出 OpenAPI 规范到 JSON 文件""" import json import sys from pathlib import Path # 添加 src 到路径 sys.path.insert(0, str(Path(__file__).parent.parent / "src")) from functional_scaffold.main import app def export_openapi(): """导出 OpenAPI 规范""" openapi_schema = app.openapi() # 确保输出目录存在 output_dir = Path(__file__).parent.parent / "docs" / "swagger" output_dir.mkdir(parents=True, exist_ok=True) # 写入文件 output_file = output_dir / "openapi.json" with open(output_file, "w", encoding="utf-8") as f: json.dump(openapi_schema, f, indent=2, ensure_ascii=False) print(f"OpenAPI schema exported to: {output_file}") print(f"Schema version: {openapi_schema.get('openapi')}") print(f"API title: {openapi_schema.get('info', {}).get('title')}") print(f"API version: {openapi_schema.get('info', {}).get('version')}") print(f"Endpoints: {len(openapi_schema.get('paths', {}))}") if __name__ == "__main__": export_openapi()