新增内容: - 创建基础项目结构。 - 添加 `.gitignore` 和 `.dockerignore` 文件。 - 编写 `pyproject.toml` 和依赖文件。 - 添加算法模块及示例算法。 - 实现核心功能模块(日志、错误处理、指标)。 - 添加开发和运行所需的相关脚本文件及文档。
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
#!/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()
|