fix:stage

This commit is contained in:
gongwenxin
2025-08-08 00:43:22 +08:00
parent 7ddb530353
commit 8df41527d6
4 changed files with 270 additions and 35 deletions
+25 -5
View File
@@ -2446,17 +2446,27 @@ class APITestOrchestrator:
if isinstance(parsed_spec, ParsedYAPISpec):
if parsed_spec.categories:
api_groups_to_iterate.extend([cat.get('name') for cat in parsed_spec.categories if cat.get('name')])
if not api_groups_to_iterate:
if not api_groups_to_iterate:
self.logger.info("YAPI规范: 未找到已命名的分类,或分类列表为空。将阶段应用于整个规范 (api_group_name=None).")
api_groups_to_iterate.append(None)
api_groups_to_iterate.append(None)
elif isinstance(parsed_spec, ParsedSwaggerSpec):
# For Swagger, iterate through globally defined tags. Stages can then filter APIs based on these tags.
# If a stage is designed for broader application, it can ignore the specific group name.
if parsed_spec.tags:
if parsed_spec.tags:
api_groups_to_iterate.extend([tag.get('name') for tag in parsed_spec.tags if tag.get('name')])
if not api_groups_to_iterate:
self.logger.info("Swagger规范: 未找到已定义的标签,或标签列表为空。将阶段应用于整个规范 (api_group_name=None).")
api_groups_to_iterate.append(None)
elif hasattr(parsed_spec, 'spec_type') and parsed_spec.spec_type == 'dms':
# 🔧 DMS特殊处理:为每个CRUD场景创建虚拟分组
from custom_stages.dms_crud_scenario_stage import DmsCrudScenarioStage
dms_scenarios = DmsCrudScenarioStage.discover_crud_scenarios(parsed_spec)
if dms_scenarios:
api_groups_to_iterate.extend([scenario['virtual_group_name'] for scenario in dms_scenarios])
self.logger.info(f"DMS规范: 发现 {len(dms_scenarios)} 个CRUD场景,创建对应的虚拟分组: {[s['virtual_group_name'] for s in dms_scenarios]}")
else:
self.logger.info("DMS规范: 未发现完整的CRUD场景,将阶段应用于整个规范 (api_group_name=None).")
api_groups_to_iterate.append(None)
else:
self.logger.warning(f"未知的解析规范类型: {type(parsed_spec)}。将阶段应用于整个规范 (api_group_name=None).")
api_groups_to_iterate.append(None)
@@ -2531,11 +2541,21 @@ class APITestOrchestrator:
current_group_metadata = {'name': current_api_group_name, 'description': '标签定义可能仅在操作上'}
apis_for_current_group_objects = [
api for api in parsed_spec.endpoints
api for api in parsed_spec.endpoints
if isinstance(api, SwaggerEndpoint) and hasattr(api, 'tags') and isinstance(api.tags, list) and current_api_group_name in api.tags
]
self.logger.debug(f"For Swagger group '{current_api_group_name}', selected {len(apis_for_current_group_objects)} endpoint objects.")
else:
elif hasattr(parsed_spec, 'spec_type') and parsed_spec.spec_type == 'dms' and current_api_group_name and current_api_group_name.startswith('dms_crud_'):
# 🔧 DMS虚拟分组处理:为特定的CRUD场景提供所有DMS端点
resource_name = current_api_group_name.replace('dms_crud_', '')
current_group_metadata = {
'name': current_api_group_name,
'description': f'DMS CRUD场景: {resource_name}'
}
# 为DMS虚拟分组提供所有DMS端点(Stage会自己过滤)
apis_for_current_group_objects = list(parsed_spec.endpoints)
self.logger.debug(f"For DMS virtual group '{current_api_group_name}', provided {len(apis_for_current_group_objects)} DMS endpoint objects.")
else:
self.logger.warning(f"Unknown spec type ({type(parsed_spec)}) for group '{current_api_group_name}'.")
current_group_metadata = {"name": current_api_group_name, "description": f"未知规范类型 ({type(parsed_spec)}) 的分组"}
else: