import json

# 读取 OpenAPI 文件
with open('results/openapi.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

# 打印基本信息
print(f"API 标题: {data['info']['title']}")
print(f"API 版本: {data['info']['version']}")
print(f"\n路径数量: {len(data['paths'])}")
print("\n接口列表:")

# 遍历所有路径和方法
for path, methods in data['paths'].items():
    for method, details in methods.items():
        summary = details.get('summary', '无描述')
        operation_id = details.get('operationId', '无操作ID')
        tags = details.get('tags', [])
        print(f"- {method.upper()} {path}")
        print(f"  摘要: {summary}")
        print(f"  操作ID: {operation_id}")
        print(f"  标签: {', '.join(tags)}")
        
        # 打印参数
        if 'parameters' in details:
            print("  参数:")
            for param in details['parameters']:
                name = param.get('name')
                in_ = param.get('in')
                required = param.get('required', False)
                print(f"    - {name} ({in_}) {'必填' if required else '可选'}")
        
        # 打印请求体
        if 'requestBody' in details:
            print("  请求体: 有")
        
        # 打印响应
        if 'responses' in details:
            print("  响应:")
            for status, resp in details['responses'].items():
                print(f"    - {status}: {resp.get('description', '无描述')}")
        
        print()

# 打印组件数量
if 'components' in data and 'schemas' in data['components']:
    print(f"\n组件数量: {len(data['components']['schemas'])}")
else:
    print("\n组件数量: 0")
