From a7b4c9825352e79f8f05a131c3951bdef731fd66 Mon Sep 17 00:00:00 2001 From: Hangfei Lin Date: Sat, 3 May 2025 22:39:00 -0700 Subject: [PATCH] fix: Handle the case when parameter.required is None and fix tests PiperOrigin-RevId: 754519323 --- .../openapi_tool/openapi_spec_parser/operation_parser.py | 3 ++- .../openapi_tool/openapi_spec_parser/test_operation_parser.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py b/src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py index 930e05c..a7bed0f 100644 --- a/src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py +++ b/src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py @@ -83,7 +83,8 @@ class OperationParser: schema.description = ( description if not schema.description else schema.description ) - required = param.required + # param.required can be None + required = param.required if param.required is not None else False self.params.append( ApiParameter( diff --git a/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py b/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py index 0c774f6..653590e 100644 --- a/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py +++ b/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py @@ -347,8 +347,8 @@ def test_get_json_schema(sample_operation): assert json_schema['type'] == 'object' assert 'param1' in json_schema['properties'] assert 'prop1' in json_schema['properties'] - assert 'param1' in json_schema['required'] - assert 'prop1' in json_schema['required'] + # By default nothing is required unless explicitly stated + assert 'required' not in json_schema or json_schema['required'] == [] def test_get_signature_parameters(sample_operation):