update swagger
This commit is contained in:
34
test_openapi.py
Normal file
34
test_openapi.py
Normal 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()
|
||||
Reference in New Issue
Block a user