fix:列表查询

This commit is contained in:
gongwenxin 2025-08-08 15:35:09 +08:00
parent 4bf7ee9988
commit e776736966
4 changed files with 29 additions and 775554 deletions

View File

@ -213,15 +213,28 @@ class DmsCrudScenarioStage(BaseAPIStage):
op_type, resource_name = parts op_type, resource_name = parts
grouped_ops[resource_name][op_type] = ep grouped_ops[resource_name][op_type] = ep
# 找到完整的CRUD场景 # 🔧 找到完整的CRUD场景支持单主键和多主键模型
required_ops = {'create', 'read', 'update', 'delete', 'list'}
scenarios = [] scenarios = []
for resource_name, ops in grouped_ops.items(): for resource_name, ops in grouped_ops.items():
if required_ops.issubset(ops.keys()): # 检查是否有基本的CRUD操作
basic_ops = {'create', 'update', 'delete', 'list'}
if basic_ops.issubset(ops.keys()):
# 检查是否有read操作单主键模型有多主键模型没有
if 'read' in ops:
# 单主键模型完整的5个操作
scenario_type = "单主键CRUD场景"
required_ops = {'create', 'read', 'update', 'delete', 'list'}
else:
# 多主键模型4个操作没有read
scenario_type = "多主键CRUD场景"
required_ops = basic_ops
scenarios.append({ scenarios.append({
'resource_name': resource_name, 'resource_name': resource_name,
'endpoints': ops, 'endpoints': ops,
'virtual_group_name': f"dms_crud_{resource_name}" 'virtual_group_name': f"dms_crud_{resource_name}",
'scenario_type': scenario_type,
'required_ops': required_ops
}) })
return scenarios return scenarios

View File

@ -683,35 +683,27 @@ class InputParser:
create_request_body_schema = {"type": "object", "properties": {"version": {"type": "string", "example": version}, "act": {"type": "integer", "example": 0}, "data": {"type": "array", "items": model}}, "required": ["data"]} create_request_body_schema = {"type": "object", "properties": {"version": {"type": "string", "example": version}, "act": {"type": "integer", "example": 0}, "data": {"type": "array", "items": model}}, "required": ["data"]}
endpoints.append(DMSEndpoint(path=create_path, method='post', title=f"Create {name}", request_body={'content': {'application/json': {'schema': create_request_body_schema}}}, responses=success_response, test_mode='scenario_only', operation_id=f"create_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list)) endpoints.append(DMSEndpoint(path=create_path, method='post', title=f"Create {name}", request_body={'content': {'application/json': {'schema': create_request_body_schema}}}, responses=success_response, test_mode='scenario_only', operation_id=f"create_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list))
# List Endpoint (POST) # List Endpoint (POST) - 🔧 添加pageNo和pageSize查询参数
list_path = f"/api/dms/{dms_instance_code}/v1/{name}/{version}" list_path = f"/api/dms/{dms_instance_code}/v1/{name}/{version}"
list_response_schema = {"type": "object", "properties": {"code": {"type": "integer"}, "message": {"type": "string"}, "data": {"type": "array", "items": model}}} list_response_schema = {"type": "object", "properties": {"code": {"type": "integer"}, "message": {"type": "string"}, "data": {"type": "array", "items": model}}}
endpoints.append(DMSEndpoint(path=list_path, method='post', title=f"List {name}", request_body={'content': {'application/json': {'schema': {}}}}, responses={'200': {'description': 'Successful Operation', 'content': {'application/json': {'schema': list_response_schema}}}}, test_mode='standalone', operation_id=f"list_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list)) list_parameters = [
{'name': 'pageNo', 'in': 'query', 'required': False, 'description': '页码(从1开始)', 'schema': {'type': 'integer', 'default': 1}},
{'name': 'pageSize', 'in': 'query', 'required': False, 'description': '分页大小(最大值200)', 'schema': {'type': 'integer', 'default': 1000}}
]
endpoints.append(DMSEndpoint(path=list_path, method='post', title=f"List {name}", request_body={'content': {'application/json': {'schema': {}}}}, responses={'200': {'description': 'Successful Operation', 'content': {'application/json': {'schema': list_response_schema}}}}, parameters=list_parameters, test_mode='standalone', operation_id=f"list_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list))
# Read Endpoint (GET) # Read Endpoint (GET) - 🔧 只为单主键模型生成查询详情接口
if isinstance(identity_id_list, list) and len(identity_id_list) > 1: if isinstance(identity_id_list, list) and len(identity_id_list) > 1:
# 多主键:使用复合路径参数 # 🚫 多主键模型:不生成查询详情接口
path_params = [] self.logger.info(f"跳过多主键模型 '{name}' 的查询详情接口生成,主键数量: {len(identity_id_list)}")
read_parameters = []
for pk_field in identity_id_list:
path_params.append(f"{{{pk_field}}}")
if pk_field in model['properties']:
pk_field_schema = model['properties'][pk_field]
else:
pk_field_schema = {"type": "string"}
read_parameters.append({'name': pk_field, 'in': 'path', 'required': True, 'description': f'The {pk_field} of the {name}', 'schema': pk_field_schema})
read_path = f"/api/dms/{dms_instance_code}/v1/{name}/{version}/" + "/".join(path_params)
self.logger.info(f"创建多主键读取端点 '{name}',路径参数: {identity_id_list}")
else: else:
# 单主键使用单个id参数 # ✅ 单主键模型:生成查询详情接口
read_path = f"/api/dms/{dms_instance_code}/v1/{name}/{version}/{{id}}" read_path = f"/api/dms/{dms_instance_code}/v1/{name}/{version}/{{id}}"
read_parameters = [{'name': 'id', 'in': 'path', 'required': True, 'description': f'The ID of the {name}, maps to {pk_name}', 'schema': pk_schema}] read_parameters = [{'name': 'id', 'in': 'path', 'required': True, 'description': f'The ID of the {name}, maps to {pk_name}', 'schema': pk_schema}]
read_response_schema = {"type": "object", "properties": {"code": {"type": "integer"}, "message": {"type": "string"}, "data": model}}
endpoints.append(DMSEndpoint(path=read_path, method='get', title=f"Read {name}", request_body=None, responses={'200': {'description': 'Successful Operation', 'content': {'application/json': {'schema': read_response_schema}}}}, parameters=read_parameters, test_mode='scenario_only', operation_id=f"read_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list))
self.logger.info(f"创建单主键读取端点 '{name}',路径参数: id") self.logger.info(f"创建单主键读取端点 '{name}',路径参数: id")
read_response_schema = {"type": "object", "properties": {"code": {"type": "integer"}, "message": {"type": "string"}, "data": model}}
endpoints.append(DMSEndpoint(path=read_path, method='get', title=f"Read {name}", request_body=None, responses={'200': {'description': 'Successful Operation', 'content': {'application/json': {'schema': read_response_schema}}}}, parameters=read_parameters, test_mode='scenario_only', operation_id=f"read_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list))
# Update Endpoint (PUT) # Update Endpoint (PUT)
update_path = f"/api/dms/{dms_instance_code}/v1/{name}" update_path = f"/api/dms/{dms_instance_code}/v1/{name}"
endpoints.append(DMSEndpoint(path=update_path, method='put', title=f"Update {name}", request_body={'content': {'application/json': {'schema': create_request_body_schema}}}, responses=success_response, test_mode='scenario_only', operation_id=f"update_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list)) endpoints.append(DMSEndpoint(path=update_path, method='put', title=f"Update {name}", request_body={'content': {'application/json': {'schema': create_request_body_schema}}}, responses=success_response, test_mode='scenario_only', operation_id=f"update_{name}", category_name=category_name, raw_record=item, model_pk_name=pk_name, identity_id_list=identity_id_list))

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff