Skip to content

Commit 141d5b2

Browse files
committed
fix: Update SDK code to read from the correct AdditionalProperties key
1 parent 0a50892 commit 141d5b2

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

packages/toolbox-core/src/toolbox_core/protocol.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from inspect import Parameter
16-
from typing import Any, Optional, Type
16+
from typing import Any, Optional, Type, Union
1717

1818
from pydantic import BaseModel
1919

@@ -29,7 +29,7 @@ class ParameterSchema(BaseModel):
2929
description: str
3030
authSources: Optional[list[str]] = None
3131
items: Optional["ParameterSchema"] = None
32-
valueType: Optional[str] = None
32+
AdditionalProperties: Optional[Union[bool, "ParameterSchema"]] = None
3333

3434
def __get_type(self) -> Type:
3535
base_type: Type
@@ -46,17 +46,9 @@ def __get_type(self) -> Type:
4646
raise Exception("Unexpected value: type is 'list' but items is None")
4747
base_type = list[self.items.__get_type()] # type: ignore
4848
elif self.type == "object":
49-
if self.valueType:
50-
if self.valueType == "string":
51-
base_type = dict[str, str]
52-
elif self.valueType == "integer":
53-
base_type = dict[str, int]
54-
elif self.valueType == "float":
55-
base_type = dict[str, float]
56-
elif self.valueType == "boolean":
57-
base_type = dict[str, bool]
58-
else:
59-
raise ValueError(f"Unsupported map value type: {self.valueType}")
49+
if isinstance(self.AdditionalProperties, ParameterSchema):
50+
value_type = self.AdditionalProperties.__get_type()
51+
base_type = dict[str, value_type]
6052
else:
6153
base_type = dict[str, Any]
6254
else:

packages/toolbox-core/tests/test_protocol.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ def test_parameter_schema_array_optional():
173173

174174

175175
def test_parameter_schema_map_generic():
176-
"""Tests ParameterSchema with a generic 'map' type."""
177-
schema = ParameterSchema(name="metadata", type="map", description="Some metadata")
176+
"""Tests ParameterSchema with a generic 'object' type."""
177+
schema = ParameterSchema(
178+
name="metadata",
179+
type="object",
180+
description="Some metadata",
181+
AdditionalProperties=True,
182+
)
178183
expected_type = dict[str, Any]
179184
assert schema._ParameterSchema__get_type() == expected_type
180185

@@ -186,12 +191,12 @@ def test_parameter_schema_map_generic():
186191

187192

188193
def test_parameter_schema_map_typed_string():
189-
"""Tests ParameterSchema with a typed 'map' type (string values)."""
194+
"""Tests ParameterSchema with a typed 'object' type (string values)."""
190195
schema = ParameterSchema(
191196
name="headers",
192-
type="map",
197+
type="object",
193198
description="HTTP headers",
194-
valueType="string",
199+
AdditionalProperties=ParameterSchema(name="", type="string", description=""),
195200
)
196201
expected_type = dict[str, str]
197202
assert schema._ParameterSchema__get_type() == expected_type
@@ -201,12 +206,12 @@ def test_parameter_schema_map_typed_string():
201206

202207

203208
def test_parameter_schema_map_typed_integer():
204-
"""Tests ParameterSchema with a typed 'map' type (integer values)."""
209+
"""Tests ParameterSchema with a typed 'object' type (integer values)."""
205210
schema = ParameterSchema(
206211
name="user_scores",
207-
type="map",
212+
type="object",
208213
description="User scores",
209-
valueType="integer",
214+
AdditionalProperties=ParameterSchema(name="", type="integer", description=""),
210215
)
211216
expected_type = dict[str, int]
212217
assert schema._ParameterSchema__get_type() == expected_type
@@ -215,12 +220,12 @@ def test_parameter_schema_map_typed_integer():
215220

216221

217222
def test_parameter_schema_map_typed_float():
218-
"""Tests ParameterSchema with a typed 'map' type (float values)."""
223+
"""Tests ParameterSchema with a typed 'object' type (float values)."""
219224
schema = ParameterSchema(
220225
name="item_prices",
221-
type="map",
226+
type="object",
222227
description="Item prices",
223-
valueType="float",
228+
AdditionalProperties=ParameterSchema(name="", type="float", description=""),
224229
)
225230
expected_type = dict[str, float]
226231
assert schema._ParameterSchema__get_type() == expected_type
@@ -229,12 +234,12 @@ def test_parameter_schema_map_typed_float():
229234

230235

231236
def test_parameter_schema_map_typed_boolean():
232-
"""Tests ParameterSchema with a typed 'map' type (boolean values)."""
237+
"""Tests ParameterSchema with a typed 'object' type (boolean values)."""
233238
schema = ParameterSchema(
234239
name="feature_flags",
235-
type="map",
240+
type="object",
236241
description="Feature flags",
237-
valueType="boolean",
242+
AdditionalProperties=ParameterSchema(name="", type="boolean", description=""),
238243
)
239244
expected_type = dict[str, bool]
240245
assert schema._ParameterSchema__get_type() == expected_type
@@ -243,12 +248,13 @@ def test_parameter_schema_map_typed_boolean():
243248

244249

245250
def test_parameter_schema_map_optional():
246-
"""Tests an optional ParameterSchema with a 'map' type."""
251+
"""Tests an optional ParameterSchema with a 'object' type."""
247252
schema = ParameterSchema(
248253
name="optional_metadata",
249-
type="map",
254+
type="object",
250255
description="Optional metadata",
251256
required=False,
257+
AdditionalProperties=True,
252258
)
253259
expected_type = Optional[dict[str, Any]]
254260
assert schema._ParameterSchema__get_type() == expected_type
@@ -262,10 +268,13 @@ def test_parameter_schema_map_unsupported_value_type_error():
262268
unsupported_type = "custom_object"
263269
schema = ParameterSchema(
264270
name="custom_data",
265-
type="map",
271+
type="object",
266272
description="Custom data map",
267273
valueType=unsupported_type,
274+
AdditionalProperties=ParameterSchema(
275+
name="", type=unsupported_type, description=""
276+
),
268277
)
269-
expected_error_msg = f"Unsupported map value type: {unsupported_type}"
278+
expected_error_msg = f"Unsupported schema type: {unsupported_type}"
270279
with pytest.raises(ValueError, match=expected_error_msg):
271280
schema._ParameterSchema__get_type()

0 commit comments

Comments
 (0)