fix: preserve required body properties
Merge https://github.com/google/adk-python/pull/6504 Fixes #6503 PiperOrigin-RevId: 957222383
This commit is contained in:
committed by
Copybara-Service
parent
b5be64c075
commit
9b31268d17
@@ -142,6 +142,7 @@ class OperationParser:
|
||||
|
||||
if schema and schema.type == 'object':
|
||||
properties = schema.properties or {}
|
||||
required_properties = set(schema.required or [])
|
||||
for prop_name, prop_details in properties.items():
|
||||
self._params.append(
|
||||
ApiParameter(
|
||||
@@ -149,6 +150,7 @@ class OperationParser:
|
||||
param_location='body',
|
||||
param_schema=prop_details,
|
||||
description=prop_details.description,
|
||||
required=prop_name in required_properties,
|
||||
py_name=self._get_py_name(prop_name),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -105,6 +105,31 @@ def test_process_request_body(sample_operation):
|
||||
assert parser._params[1].param_location == 'body'
|
||||
|
||||
|
||||
def test_required_request_body_properties_are_required_parameters():
|
||||
"""Required body properties appear in the generated parameter schema."""
|
||||
operation = Operation(
|
||||
operationId='createSpace',
|
||||
requestBody=RequestBody(
|
||||
content={
|
||||
'application/json': MediaType(
|
||||
schema=Schema(
|
||||
type='object',
|
||||
required=['spaceName'],
|
||||
properties={
|
||||
'spaceName': Schema(type='string'),
|
||||
'description': Schema(type='string'),
|
||||
},
|
||||
)
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
parser = OperationParser(operation)
|
||||
|
||||
assert parser.get_json_schema()['required'] == ['space_name']
|
||||
|
||||
|
||||
def test_process_request_body_array():
|
||||
"""Test _process_request_body method with array schema."""
|
||||
operation = Operation(
|
||||
|
||||
Reference in New Issue
Block a user