set param required tag to False by default

PiperOrigin-RevId: 754382785
This commit is contained in:
Xiang (Sean) Zhou 2025-05-03 10:30:59 -07:00 committed by Copybara-Service
parent 24024f7fc4
commit 5846b24b71
5 changed files with 57 additions and 57 deletions

View File

@ -27,7 +27,7 @@
### ⚠ BREAKING CHANGES ### ⚠ BREAKING CHANGES
* Auth: expose `access_token` and `refresh_token` at top level of auth * Auth: expose `access_token` and `refresh_token` at top level of auth
credentials, instead of a `dict` credentails, instead of a `dict`
([commit](https://github.com/google/adk-python/commit/956fb912e8851b139668b1ccb8db10fd252a6990)). ([commit](https://github.com/google/adk-python/commit/956fb912e8851b139668b1ccb8db10fd252a6990)).
### Features ### Features
@ -50,7 +50,7 @@
### Miscellaneous Chores ### Miscellaneous Chores
* README.md improvements. * README.md impprovements.
* Various code improvements. * Various code improvements.
* Various typo fixes. * Various typo fixes.
* Bump min version of google-genai to 1.11.0. * Bump min version of google-genai to 1.11.0.
@ -108,4 +108,4 @@
* Built-in evaluation support * Built-in evaluation support
* Development UI that makes local development easy * Development UI that makes local development easy
* Deploy to Google Cloud Run, Agent Engine * Deploy to Google Cloud Run, Agent Engine
* (Experimental) Live(Bidi) audio/video agent support and Compositional Function Calling(CFC) support * (Experimental) Live(Bidi) auido/video agent support and Compositional Function Calling(CFC) support

View File

@ -484,11 +484,9 @@ class DatabaseSessionService(BaseSessionService):
if storage_session.update_time.timestamp() > session.last_update_time: if storage_session.update_time.timestamp() > session.last_update_time:
raise ValueError( raise ValueError(
f"Session last_update_time " f"Session last_update_time {session.last_update_time} is later than"
f"{datetime.fromtimestamp(session.last_update_time):%Y-%m-%d %H:%M:%S} " f" the upate_time in storage {storage_session.update_time}"
f"is later than the update_time in storage " )
f"{storage_session.update_time:%Y-%m-%d %H:%M:%S}"
)
# Fetch states from storage # Fetch states from storage
storage_app_state = sessionFactory.get( storage_app_state = sessionFactory.get(

View File

@ -14,11 +14,7 @@
import keyword import keyword
import re import re
from typing import Any from typing import Any, Dict, List, Optional, Union
from typing import Dict
from typing import List
from typing import Optional
from typing import Union
from fastapi.openapi.models import Response from fastapi.openapi.models import Response
from fastapi.openapi.models import Schema from fastapi.openapi.models import Schema
@ -100,7 +96,7 @@ class ApiParameter(BaseModel):
py_name: Optional[str] = '' py_name: Optional[str] = ''
type_value: type[Any] = Field(default=None, init_var=False) type_value: type[Any] = Field(default=None, init_var=False)
type_hint: str = Field(default=None, init_var=False) type_hint: str = Field(default=None, init_var=False)
required: Optional[bool] = None required: bool = False
def model_post_init(self, _: Any): def model_post_init(self, _: Any):
self.py_name = ( self.py_name = (

View File

@ -17,9 +17,13 @@ from textwrap import dedent
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
from fastapi.openapi.models import Operation, Parameter, Schema from fastapi.openapi.models import Operation
from fastapi.openapi.models import Parameter
from fastapi.openapi.models import Schema
from ..common.common import ApiParameter, PydocHelper, to_snake_case from ..common.common import ApiParameter
from ..common.common import PydocHelper
from ..common.common import to_snake_case
class OperationParser: class OperationParser:
@ -76,7 +80,9 @@ class OperationParser:
description = param.description or '' description = param.description or ''
location = param.in_ or '' location = param.in_ or ''
schema = param.schema_ or {} # Use schema_ instead of .schema schema = param.schema_ or {} # Use schema_ instead of .schema
schema.description = description if schema.description is None and description != '' else schema.description schema.description = (
description if not schema.description else schema.description
)
required = param.required required = param.required
self.params.append( self.params.append(
@ -85,7 +91,7 @@ class OperationParser:
param_location=location, param_location=location,
param_schema=schema, param_schema=schema,
description=description, description=description,
required=required required=required,
) )
) )
@ -233,7 +239,7 @@ class OperationParser:
} }
return { return {
'properties': properties, 'properties': properties,
'required': [p.py_name for p in self.params if p.required is not False], 'required': [p.py_name for p in self.params if p.required],
'title': f"{self.operation.operationId or 'unnamed'}_Arguments", 'title': f"{self.operation.operationId or 'unnamed'}_Arguments",
'type': 'object', 'type': 'object',
} }

View File

@ -61,7 +61,7 @@ class TestRestApiTool:
return mock_parser return mock_parser
@pytest.fixture @pytest.fixture
def sample_endpoint(self): def sample_endpiont(self):
return OperationEndpoint( return OperationEndpoint(
base_url="https://example.com", path="/test", method="GET" base_url="https://example.com", path="/test", method="GET"
) )
@ -131,7 +131,7 @@ class TestRestApiTool:
def test_init( def test_init(
self, self,
sample_endpoint, sample_endpiont,
sample_operation, sample_operation,
sample_auth_scheme, sample_auth_scheme,
sample_auth_credential, sample_auth_credential,
@ -139,14 +139,14 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
) )
assert tool.name == "test_tool" assert tool.name == "test_tool"
assert tool.description == "Test Tool" assert tool.description == "Test Tool"
assert tool.endpoint == sample_endpoint assert tool.endpoint == sample_endpiont
assert tool.operation == sample_operation assert tool.operation == sample_operation
assert tool.auth_credential == sample_auth_credential assert tool.auth_credential == sample_auth_credential
assert tool.auth_scheme == sample_auth_scheme assert tool.auth_scheme == sample_auth_scheme
@ -154,7 +154,7 @@ class TestRestApiTool:
def test_from_parsed_operation_str( def test_from_parsed_operation_str(
self, self,
sample_endpoint, sample_endpiont,
sample_api_parameters, sample_api_parameters,
sample_return_parameter, sample_return_parameter,
sample_operation, sample_operation,
@ -162,7 +162,7 @@ class TestRestApiTool:
parsed_operation_str = json.dumps({ parsed_operation_str = json.dumps({
"name": "test_operation", "name": "test_operation",
"description": "Test Description", "description": "Test Description",
"endpoint": sample_endpoint.model_dump(), "endpoint": sample_endpiont.model_dump(),
"operation": sample_operation.model_dump(), "operation": sample_operation.model_dump(),
"auth_scheme": None, "auth_scheme": None,
"auth_credential": None, "auth_credential": None,
@ -174,12 +174,12 @@ class TestRestApiTool:
assert tool.name == "test_operation" assert tool.name == "test_operation"
def test_get_declaration( def test_get_declaration(
self, sample_endpoint, sample_operation, mock_operation_parser self, sample_endpiont, sample_operation, mock_operation_parser
): ):
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test description", description="Test description",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
should_parse_operation=False, should_parse_operation=False,
) )
@ -198,7 +198,7 @@ class TestRestApiTool:
self, self,
mock_request, mock_request,
mock_tool_context, mock_tool_context,
sample_endpoint, sample_endpiont,
sample_operation, sample_operation,
sample_auth_scheme, sample_auth_scheme,
sample_auth_credential, sample_auth_credential,
@ -210,7 +210,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
@ -228,7 +228,7 @@ class TestRestApiTool:
def test_call_auth_pending( def test_call_auth_pending(
self, self,
mock_request, mock_request,
sample_endpoint, sample_endpiont,
sample_operation, sample_operation,
sample_auth_scheme, sample_auth_scheme,
sample_auth_credential, sample_auth_credential,
@ -237,7 +237,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
@ -258,7 +258,7 @@ class TestRestApiTool:
} }
def test_prepare_request_params_query_body( def test_prepare_request_params_query_body(
self, sample_endpoint, sample_auth_credential, sample_auth_scheme self, sample_endpiont, sample_auth_credential, sample_auth_scheme
): ):
# Create a mock Operation object # Create a mock Operation object
mock_operation = Operation( mock_operation = Operation(
@ -288,7 +288,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="test", description="test",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -327,7 +327,7 @@ class TestRestApiTool:
assert request_params["params"] == {"testQueryParam": "query_value"} assert request_params["params"] == {"testQueryParam": "query_value"}
def test_prepare_request_params_array( def test_prepare_request_params_array(
self, sample_endpoint, sample_auth_scheme, sample_auth_credential self, sample_endpiont, sample_auth_scheme, sample_auth_credential
): ):
mock_operation = Operation( mock_operation = Operation(
operationId="test_op", operationId="test_op",
@ -345,7 +345,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="test", description="test",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -367,7 +367,7 @@ class TestRestApiTool:
assert request_params["json"] == ["item1", "item2"] assert request_params["json"] == ["item1", "item2"]
def test_prepare_request_params_string( def test_prepare_request_params_string(
self, sample_endpoint, sample_auth_credential, sample_auth_scheme self, sample_endpiont, sample_auth_credential, sample_auth_scheme
): ):
mock_operation = Operation( mock_operation = Operation(
operationId="test_op", operationId="test_op",
@ -380,7 +380,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -401,7 +401,7 @@ class TestRestApiTool:
assert request_params["headers"]["Content-Type"] == "text/plain" assert request_params["headers"]["Content-Type"] == "text/plain"
def test_prepare_request_params_form_data( def test_prepare_request_params_form_data(
self, sample_endpoint, sample_auth_scheme, sample_auth_credential self, sample_endpiont, sample_auth_scheme, sample_auth_credential
): ):
mock_operation = Operation( mock_operation = Operation(
operationId="test_op", operationId="test_op",
@ -419,7 +419,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="test", description="test",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -443,7 +443,7 @@ class TestRestApiTool:
) )
def test_prepare_request_params_multipart( def test_prepare_request_params_multipart(
self, sample_endpoint, sample_auth_credential, sample_auth_scheme self, sample_endpiont, sample_auth_credential, sample_auth_scheme
): ):
mock_operation = Operation( mock_operation = Operation(
operationId="test_op", operationId="test_op",
@ -465,7 +465,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="test", description="test",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -486,7 +486,7 @@ class TestRestApiTool:
assert request_params["headers"]["Content-Type"] == "multipart/form-data" assert request_params["headers"]["Content-Type"] == "multipart/form-data"
def test_prepare_request_params_octet_stream( def test_prepare_request_params_octet_stream(
self, sample_endpoint, sample_auth_scheme, sample_auth_credential self, sample_endpiont, sample_auth_scheme, sample_auth_credential
): ):
mock_operation = Operation( mock_operation = Operation(
operationId="test_op", operationId="test_op",
@ -501,7 +501,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="test", description="test",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -524,13 +524,13 @@ class TestRestApiTool:
) )
def test_prepare_request_params_path_param( def test_prepare_request_params_path_param(
self, sample_endpoint, sample_auth_credential, sample_auth_scheme self, sample_endpiont, sample_auth_credential, sample_auth_scheme
): ):
mock_operation = Operation(operationId="test_op") mock_operation = Operation(operationId="test_op")
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -557,7 +557,7 @@ class TestRestApiTool:
def test_prepare_request_params_header_param( def test_prepare_request_params_header_param(
self, self,
sample_endpoint, sample_endpiont,
sample_auth_credential, sample_auth_credential,
sample_auth_scheme, sample_auth_scheme,
sample_operation, sample_operation,
@ -565,7 +565,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -586,7 +586,7 @@ class TestRestApiTool:
def test_prepare_request_params_cookie_param( def test_prepare_request_params_cookie_param(
self, self,
sample_endpoint, sample_endpiont,
sample_auth_credential, sample_auth_credential,
sample_auth_scheme, sample_auth_scheme,
sample_operation, sample_operation,
@ -594,7 +594,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -614,7 +614,7 @@ class TestRestApiTool:
assert request_params["cookies"]["session_id"] == "cookie_value" assert request_params["cookies"]["session_id"] == "cookie_value"
def test_prepare_request_params_multiple_mime_types( def test_prepare_request_params_multiple_mime_types(
self, sample_endpoint, sample_auth_credential, sample_auth_scheme self, sample_endpiont, sample_auth_credential, sample_auth_scheme
): ):
# Test what happens when multiple mime types are specified. It should take # Test what happens when multiple mime types are specified. It should take
# the first one. # the first one.
@ -632,7 +632,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=mock_operation, operation=mock_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -653,7 +653,7 @@ class TestRestApiTool:
def test_prepare_request_params_unknown_parameter( def test_prepare_request_params_unknown_parameter(
self, self,
sample_endpoint, sample_endpiont,
sample_auth_credential, sample_auth_credential,
sample_auth_scheme, sample_auth_scheme,
sample_operation, sample_operation,
@ -661,7 +661,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -719,7 +719,7 @@ class TestRestApiTool:
def test_prepare_request_params_no_unrecognized_query_parameter( def test_prepare_request_params_no_unrecognized_query_parameter(
self, self,
sample_endpoint, sample_endpiont,
sample_auth_credential, sample_auth_credential,
sample_auth_scheme, sample_auth_scheme,
sample_operation, sample_operation,
@ -727,7 +727,7 @@ class TestRestApiTool:
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_credential=sample_auth_credential, auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme, auth_scheme=sample_auth_scheme,
@ -748,13 +748,13 @@ class TestRestApiTool:
def test_prepare_request_params_no_credential( def test_prepare_request_params_no_credential(
self, self,
sample_endpoint, sample_endpiont,
sample_operation, sample_operation,
): ):
tool = RestApiTool( tool = RestApiTool(
name="test_tool", name="test_tool",
description="Test Tool", description="Test Tool",
endpoint=sample_endpoint, endpoint=sample_endpiont,
operation=sample_operation, operation=sample_operation,
auth_credential=None, auth_credential=None,
auth_scheme=None, auth_scheme=None,