Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| 检查 API 文档和规范 | |
| """ | |
| import requests | |
| import json | |
| def check_openapi_spec(): | |
| """检查 OpenAPI 规范""" | |
| try: | |
| response = requests.get("http://localhost:8000/openapi.json", timeout=10) | |
| if response.status_code == 200: | |
| spec = response.json() | |
| print("📋 OpenAPI 规范分析") | |
| print("=" * 50) | |
| # 查找模型相关的信息 | |
| def find_model_info(obj, path=""): | |
| models_found = [] | |
| if isinstance(obj, dict): | |
| for key, value in obj.items(): | |
| current_path = f"{path}.{key}" if path else key | |
| if "model" in key.lower() or "claude" in key.lower() or "anthropic" in key.lower(): | |
| models_found.append((current_path, value)) | |
| models_found.extend(find_model_info(value, current_path)) | |
| elif isinstance(obj, list): | |
| for i, item in enumerate(obj): | |
| models_found.extend(find_model_info(item, f"{path}[{i}]")) | |
| return models_found | |
| model_info = find_model_info(spec) | |
| if model_info: | |
| print("🔍 发现模型相关信息:") | |
| for path, value in model_info[:10]: # 只显示前10个 | |
| print(f" {path}: {value}") | |
| else: | |
| print("❌ 未在 OpenAPI 规范中发现模型信息") | |
| # 检查 schemas | |
| if "components" in spec and "schemas" in spec["components"]: | |
| schemas = spec["components"]["schemas"] | |
| print(f"\n📝 发现 {len(schemas)} 个 schema:") | |
| for schema_name in schemas.keys(): | |
| print(f" • {schema_name}") | |
| # 保存完整规范 | |
| with open("openapi_spec.json", "w", encoding="utf-8") as f: | |
| json.dump(spec, f, ensure_ascii=False, indent=2) | |
| print(f"\n📁 完整 OpenAPI 规范已保存到: openapi_spec.json") | |
| else: | |
| print(f"❌ 获取 OpenAPI 规范失败: {response.status_code}") | |
| except Exception as e: | |
| print(f"❌ 检查 OpenAPI 规范异常: {e}") | |
| def check_docs_page(): | |
| """检查文档页面""" | |
| try: | |
| response = requests.get("http://localhost:8000/docs", timeout=10) | |
| if response.status_code == 200: | |
| print("📖 /docs 页面可访问") | |
| print("建议在浏览器中访问 http://localhost:8000/docs 查看完整文档") | |
| else: | |
| print(f"❌ /docs 页面不可访问: {response.status_code}") | |
| except Exception as e: | |
| print(f"❌ 检查 /docs 页面异常: {e}") | |
| if __name__ == "__main__": | |
| check_openapi_spec() | |
| check_docs_page() | |