Skip to content

Commit 7604e0e

Browse files
author
Doug Borg
committed
fix: improve error message for missing operationId
Address review feedback by making the error message more helpful when operationId and path_name are both missing. The error now includes: - Operation summary (if present) - HTTP operation (get, post, etc.) - Path name value This helps developers quickly identify which operation in their OpenAPI spec needs to be fixed. Also adds test coverage to verify the improved error message includes all expected details.
1 parent 9f0b5a4 commit 7604e0e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/openapi_python_generator/language_converters/python/service_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ def generate_operation_id(
248248
# Insert underscore before parameter placeholders so /lists/{listId} -> lists_{listId}
249249
cleaned = re.sub(r"\{([^}]+)\}", r"_\1", path_name)
250250
return common.normalize_symbol(f"{http_op}_{cleaned}")
251-
raise RuntimeError("Missing operationId and path_name for operation")
251+
raise RuntimeError(
252+
f"Missing operationId and path_name for operation. "
253+
f"Details: summary={getattr(operation, 'summary', None)!r}, "
254+
f"http_op={http_op!r}, path_name={path_name!r}"
255+
)
252256

253257

254258
def _generate_params(

tests/test_service_generator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,20 @@ def test_generate_operation_id_path_param_separator():
497497
op = Operation(responses=default_responses, operationId=None) # type: ignore[arg-type]
498498
op_id = generate_operation_id(op, "get", path_name)
499499
assert op_id == "get_lists_listId"
500+
501+
502+
def test_generate_operation_id_error_message_includes_details():
503+
"""Error message should include operation details to help identify problematic operations."""
504+
op = Operation(
505+
responses=default_responses, operationId=None, summary="Get user data" # type: ignore[arg-type]
506+
)
507+
try:
508+
generate_operation_id(op, "get", None)
509+
assert False, "Expected RuntimeError to be raised"
510+
except RuntimeError as e:
511+
error_msg = str(e)
512+
# Verify error message includes helpful details
513+
assert "Missing operationId and path_name" in error_msg
514+
assert "summary='Get user data'" in error_msg
515+
assert "http_op='get'" in error_msg
516+
assert "path_name=None" in error_msg

0 commit comments

Comments
 (0)