添加error 测试用例,但是测试用例太复杂,还需要优化框架

This commit is contained in:
gongwenxin
2025-05-23 12:05:48 +08:00
parent 0e3e721bc0
commit 4180a0ce81
37 changed files with 45453 additions and 499 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
import json
def remove_refs_from_dict(data):
if isinstance(data, dict):
# Create a copy of keys to iterate over, as we might modify the dict
keys = list(data.keys())
for key in keys:
if key == "$ref" or key == "$$ref":
del data[key]
else:
remove_refs_from_dict(data[key])
elif isinstance(data, list):
for item in data:
remove_refs_from_dict(item)
return data
input_file = "doc/井筒API示例swagger_fixed_simple.json"
output_file = "doc/井筒API示例swagger_fixed_simple_noref_processed.json" # 输出到新文件
try:
with open(input_file, 'r', encoding='utf-8') as f:
json_data = json.load(f)
processed_data = remove_refs_from_dict(json_data)
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(processed_data, f, ensure_ascii=False, indent=2)
print(f"成功处理文件,移除了 '$ref''$$ref' 字段。结果已保存到: {output_file}")
except FileNotFoundError:
print(f"错误: 输入文件未找到: {input_file}")
except json.JSONDecodeError:
print(f"错误: 输入文件 '{input_file}' 不是有效的 JSON 格式。")
except Exception as e:
print(f"处理过程中发生错误: {e}")