update swagger

This commit is contained in:
2026-03-26 15:42:37 +08:00
parent e0af97ac7f
commit d8db141423
8 changed files with 1274 additions and 190 deletions

34
test_openapi.py Normal file
View File

@@ -0,0 +1,34 @@
"""
测试 OpenAPI schema 生成
使用方法python test_openapi.py
"""
try:
from app.main import app
import json
# 生成 OpenAPI schema
schema = app.openapi()
print("✅ OpenAPI schema 生成成功!")
print(f"\n📊 API 路径数量:{len(schema['paths'])}")
print(f"\n📝 可用的 API 路径:")
for path in sorted(schema['paths'].keys()):
methods = list(schema['paths'][path].keys())
print(f" - {path} [{', '.join(methods)}]")
# 保存 schema 到文件
with open('openapi_schema.json', 'w', encoding='utf-8') as f:
json.dump(schema, f, ensure_ascii=False, indent=2)
print(f"\n💾 Schema 已保存到openapi_schema.json")
print(f"\n🌐 启动服务后访问:")
print(f" - Swagger UI: http://localhost:8000/docs")
print(f" - ReDoc: http://localhost:8000/redoc")
print(f" - OpenAPI JSON: http://localhost:8000/openapi.json")
except Exception as e:
print(f"❌ 错误:{e}")
import traceback
traceback.print_exc()