Skip to content

Commit 3568c92

Browse files
Merge pull request #547 from jeffreyrubi:fix/missing-path-level-parameters
PiperOrigin-RevId: 784415343
2 parents d0a330c + 6f01660 commit 3568c92

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def _collect_operations(
111111
if operation_dict is None:
112112
continue
113113

114+
# Append path-level parameters
115+
operation_dict["parameters"] = operation_dict.get(
116+
"parameters", []
117+
) + path_item.get("parameters", [])
118+
114119
# If operation ID is missing, assign an operation id based on path
115120
# and method
116121
if "operationId" not in operation_dict:

tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,3 +624,60 @@ def test_parse_spec_with_duplicate_parameter_names(openapi_spec_generator):
624624
assert body_param is not None
625625
assert body_param.original_name == "name"
626626
assert body_param.py_name == "name_0"
627+
628+
629+
def test_parse_spec_with_path_level_parameters(openapi_spec_generator):
630+
"""Test that operation parameters are correctly combined with path-level parameters."""
631+
openapi_spec = {
632+
"openapi": "3.1.0",
633+
"info": {"title": "Combine Parameters API", "version": "1.0.0"},
634+
"paths": {
635+
"/test": {
636+
"parameters": [{
637+
"name": "global_param",
638+
"in": "query",
639+
"schema": {"type": "string"},
640+
}],
641+
"get": {
642+
"parameters": [{
643+
"name": "local_param",
644+
"in": "header",
645+
"schema": {"type": "integer"},
646+
}],
647+
"operationId": "testGet",
648+
"responses": {
649+
"200": {
650+
"description": "Successful response",
651+
"content": {
652+
"application/json": {"schema": {"type": "string"}}
653+
},
654+
}
655+
},
656+
},
657+
}
658+
},
659+
}
660+
661+
parsed_operations = openapi_spec_generator.parse(openapi_spec)
662+
assert len(parsed_operations) == 1
663+
664+
operation = parsed_operations[0]
665+
assert len(operation.parameters) == 2
666+
667+
# Verify the combined parameters
668+
global_param = next(
669+
(p for p in operation.parameters if p.original_name == "global_param"),
670+
None,
671+
)
672+
local_param = next(
673+
(p for p in operation.parameters if p.original_name == "local_param"),
674+
None,
675+
)
676+
677+
assert global_param is not None
678+
assert global_param.param_location == "query"
679+
assert global_param.type_value is str
680+
681+
assert local_param is not None
682+
assert local_param.param_location == "header"
683+
assert local_param.type_value is int

tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_toolset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_openapi_toolset_tool_existing(openapi_spec: Dict):
9595
assert tool.is_long_running is False
9696
assert tool.operation.operationId == "calendar.calendars.get"
9797
assert tool.operation.description == "Returns metadata for a calendar."
98-
assert len(tool.operation.parameters) == 1
98+
assert len(tool.operation.parameters) == 8
9999
assert tool.operation.parameters[0].name == "calendarId"
100100
assert tool.operation.parameters[0].in_ == ParameterInType.path
101101
assert tool.operation.parameters[0].required is True

0 commit comments

Comments
 (0)