Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(py): handle typeless and empty combiner schemas in openapi signatures (#3710)

Anas Khanc660007c7158
diff --git a/python/composio/utils/openapi.py b/python/composio/utils/openapi.py
index 5ab9271bb..64bb11aa6 100644
--- a/python/composio/utils/openapi.py
+++ b/python/composio/utils/openapi.py
@@ -38,7 +38,7 @@ def _type_to_parameter(schema: t.Dict[str, t.Any]) -> t.Any:
if "enum" in schema:
return _handle_enum_type(schema=schema)
- p_type = schema["type"]
+ p_type = schema.get("type")
if p_type in OPENAPI_TO_PYTHON:
return OPENAPI_TO_PYTHON[p_type]
@@ -48,10 +48,18 @@ def _type_to_parameter(schema: t.Dict[str, t.Any]) -> t.Any:
if p_type == "array":
return _handle_array_type(schema=schema)
+ if p_type is None:
+ # No type specified (e.g. a combiner option that is description-only or
+ # an explicit Any), mirroring the top-level fallback below.
+ return t.Any
+
raise InvalidSchemaError(f"Invalid property type {p_type}: {schema!r}")
def _handle_composite_type(schemas: t.List[t.Dict]) -> t.Any:
+ if not schemas:
+ # An empty oneOf/anyOf has no options to union; fall back to Any.
+ return t.Any
return t.Union[tuple(map(_type_to_parameter, schemas))]
diff --git a/python/tests/test_openapi.py b/python/tests/test_openapi.py
new file mode 100644
index 000000000..0c911d588
--- /dev/null
+++ b/python/tests/test_openapi.py
@@ -0,0 +1,108 @@
+"""Tests for :func:`composio.utils.openapi.function_signature_from_jsonschema`.
+
+This builder is what the ``google_adk`` provider uses to attach a
+``__signature__`` to wrapped tools, so a crash here fails tool wrapping. The
+top-level "no type" property already falls back to ``Any``; these tests cover
+the nested combiner options (``oneOf``/``anyOf``/``allOf``) that used to raise.
+"""
+
+import typing as t
+
+import pytest
+
+from composio.utils.openapi import function_signature_from_jsonschema
+
+
+def _annotation(prop: t.Dict[str, t.Any]) -> t.Any:
+ params = function_signature_from_jsonschema({"properties": {"x": prop}})
+ return params[0].annotation
+
+
+class TestTypelessCombinerOptions:
+ """A combiner option without a ``type`` key should default to Any, not raise."""
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_typeless_any_of_option_defaults_to_any(self):
+ annotation = _annotation(
+ {"anyOf": [{"description": "free form"}, {"type": "string"}]}
+ )
+ assert annotation == t.Union[t.Any, str]
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_typeless_one_of_option_defaults_to_any(self):
+ annotation = _annotation(
+ {"oneOf": [{"type": "string"}, {"description": "free form"}]}
+ )
+ assert annotation == t.Union[str, t.Any]
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_empty_all_of_resolves_to_any(self):
+ assert _annotation({"allOf": []}) is t.Any
+
+
+class TestEmptyCombinerLists:
+ """An empty oneOf/anyOf has no options to union; fall back to Any."""
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_empty_any_of(self):
+ assert _annotation({"anyOf": []}) is t.Any
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_empty_one_of(self):
+ assert _annotation({"oneOf": []}) is t.Any
+
+
+class TestExistingShapesUnchanged:
+ """Shapes that already worked must keep resolving identically."""
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_nullable_any_of_is_optional(self):
+ assert (
+ _annotation({"anyOf": [{"type": "string"}, {"type": "null"}]})
+ == t.Optional[str]
+ )
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_multi_member_one_of(self):
+ annotation = _annotation(
+ {
+ "oneOf": [
+ {"type": "string"},
+ {"type": "integer"},
+ {"type": "boolean"},
+ {"type": "number"},
+ ]
+ }
+ )
+ assert annotation == t.Union[str, int, bool, float]
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_enum(self):
+ assert (
+ _annotation({"type": "string", "enum": ["a", "b"]}) == t.Literal["a", "b"]
+ )
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_array(self):
+ assert (
+ _annotation({"type": "array", "items": {"type": "string"}}) == t.List[str]
+ )
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_object(self):
+ assert _annotation({"type": "object"}) == t.Dict[str, t.Any]
+
+ @pytest.mark.unit
+ @pytest.mark.schema
+ def test_typeless_property_is_any(self):
+ assert _annotation({"description": "free form"}) is t.Any