@devries-cameron20 / composio-1 / commits / c660007c7
Fork 0

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)

### Summary `function_signature_from_jsonschema` in `python/composio/utils/openapi.py` builds the `__signature__` for tools wrapped by the `google_adk` provider (`providers/google_adk/composio_google_adk/provider.py:66`). It already falls back to `Any` for a top-level property with no `type`, but the nested combiner helpers do not, so real combiner shapes crash at wrap time: - a `oneOf`/`anyOf` option with no `type` key -> `KeyError: 'type'` - an empty `oneOf`/`anyOf` list -> `TypeError: Cannot take a Union of no types` - an empty `allOf` list -> `KeyError: 'type'` (merges to `{}`) This extends the existing "default to Any" intent to nested options. Follow-up to #3708, which fixed the same bug family in `shared.py` and noted this `openapi.py` case for a separate PR. Fixes # ### Changes - `_type_to_parameter`: read `schema.get("type")` instead of `schema["type"]`; when the type is missing, return `t.Any` (mirrors the top-level fallback). An unknown *string* type still raises `InvalidSchemaError`. - `_handle_composite_type`: return `t.Any` for an empty option list instead of building an empty `Union`. Empty `allOf` merges to `{}` and resolves to `Any` via the above. - New `python/tests/test_openapi.py` (11 tests): this builder had none. Asserts the five former crashes now resolve to `Any`, and that existing shapes are unchanged. ### Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ### How Has This Been Tested? From `python/`: ``` uv run pytest tests/test_openapi.py -q # 11 passed make chk # ruff + mypy -> clean ``` To confirm the tests guard the fix, the five former crashes (typeless `anyOf`/`oneOf` option, empty `anyOf`/`oneOf`/`allOf`) raise on the unmodified file and now resolve to `Any`; regressions cover `anyOf:[str,null]` -> `Optional[str]`, a 4-member union, enum, array, object, and a typeless property. ### Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [ ] I updated documentation as needed (internal util) - [x] I added tests (new test_openapi.py) - [ ] I added a changeset (Python-only, not needed) Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>

Anas Khan committed Jul 2, 2026 at 13:10 UTC c660007c7158d7579b4e6e01841910f065b88ccc
2 files changed +117 -1
python/composio/utils/openapi.py
+9 -1
@@ -38,7 +38,7 @@ def _type_to_parameter(schema: t.Dict[str, t.Any]) -> t.Any:
38 if "enum" in schema:
39 return _handle_enum_type(schema=schema)
40
41 - p_type = schema["type"]
41 + p_type = schema.get("type")
42 if p_type in OPENAPI_TO_PYTHON:
43 return OPENAPI_TO_PYTHON[p_type]
44
@@ -48,10 +48,18 @@ def _type_to_parameter(schema: t.Dict[str, t.Any]) -> t.Any:
48 if p_type == "array":
49 return _handle_array_type(schema=schema)
50
51 + if p_type is None:
52 + # No type specified (e.g. a combiner option that is description-only or
53 + # an explicit Any), mirroring the top-level fallback below.
54 + return t.Any
55 +
56 raise InvalidSchemaError(f"Invalid property type {p_type}: {schema!r}")
57
58
59 def _handle_composite_type(schemas: t.List[t.Dict]) -> t.Any:
60 + if not schemas:
61 + # An empty oneOf/anyOf has no options to union; fall back to Any.
62 + return t.Any
63 return t.Union[tuple(map(_type_to_parameter, schemas))]
64
65
python/tests/test_openapi.py new
+108
@@ -0,0 +1,108 @@
1 +"""Tests for :func:`composio.utils.openapi.function_signature_from_jsonschema`.
2 +
3 +This builder is what the ``google_adk`` provider uses to attach a
4 +``__signature__`` to wrapped tools, so a crash here fails tool wrapping. The
5 +top-level "no type" property already falls back to ``Any``; these tests cover
6 +the nested combiner options (``oneOf``/``anyOf``/``allOf``) that used to raise.
7 +"""
8 +
9 +import typing as t
10 +
11 +import pytest
12 +
13 +from composio.utils.openapi import function_signature_from_jsonschema
14 +
15 +
16 +def _annotation(prop: t.Dict[str, t.Any]) -> t.Any:
17 + params = function_signature_from_jsonschema({"properties": {"x": prop}})
18 + return params[0].annotation
19 +
20 +
21 +class TestTypelessCombinerOptions:
22 + """A combiner option without a ``type`` key should default to Any, not raise."""
23 +
24 + @pytest.mark.unit
25 + @pytest.mark.schema
26 + def test_typeless_any_of_option_defaults_to_any(self):
27 + annotation = _annotation(
28 + {"anyOf": [{"description": "free form"}, {"type": "string"}]}
29 + )
30 + assert annotation == t.Union[t.Any, str]
31 +
32 + @pytest.mark.unit
33 + @pytest.mark.schema
34 + def test_typeless_one_of_option_defaults_to_any(self):
35 + annotation = _annotation(
36 + {"oneOf": [{"type": "string"}, {"description": "free form"}]}
37 + )
38 + assert annotation == t.Union[str, t.Any]
39 +
40 + @pytest.mark.unit
41 + @pytest.mark.schema
42 + def test_empty_all_of_resolves_to_any(self):
43 + assert _annotation({"allOf": []}) is t.Any
44 +
45 +
46 +class TestEmptyCombinerLists:
47 + """An empty oneOf/anyOf has no options to union; fall back to Any."""
48 +
49 + @pytest.mark.unit
50 + @pytest.mark.schema
51 + def test_empty_any_of(self):
52 + assert _annotation({"anyOf": []}) is t.Any
53 +
54 + @pytest.mark.unit
55 + @pytest.mark.schema
56 + def test_empty_one_of(self):
57 + assert _annotation({"oneOf": []}) is t.Any
58 +
59 +
60 +class TestExistingShapesUnchanged:
61 + """Shapes that already worked must keep resolving identically."""
62 +
63 + @pytest.mark.unit
64 + @pytest.mark.schema
65 + def test_nullable_any_of_is_optional(self):
66 + assert (
67 + _annotation({"anyOf": [{"type": "string"}, {"type": "null"}]})
68 + == t.Optional[str]
69 + )
70 +
71 + @pytest.mark.unit
72 + @pytest.mark.schema
73 + def test_multi_member_one_of(self):
74 + annotation = _annotation(
75 + {
76 + "oneOf": [
77 + {"type": "string"},
78 + {"type": "integer"},
79 + {"type": "boolean"},
80 + {"type": "number"},
81 + ]
82 + }
83 + )
84 + assert annotation == t.Union[str, int, bool, float]
85 +
86 + @pytest.mark.unit
87 + @pytest.mark.schema
88 + def test_enum(self):
89 + assert (
90 + _annotation({"type": "string", "enum": ["a", "b"]}) == t.Literal["a", "b"]
91 + )
92 +
93 + @pytest.mark.unit
94 + @pytest.mark.schema
95 + def test_array(self):
96 + assert (
97 + _annotation({"type": "array", "items": {"type": "string"}}) == t.List[str]
98 + )
99 +
100 + @pytest.mark.unit
101 + @pytest.mark.schema
102 + def test_object(self):
103 + assert _annotation({"type": "object"}) == t.Dict[str, t.Any]
104 +
105 + @pytest.mark.unit
106 + @pytest.mark.schema
107 + def test_typeless_property_is_any(self):
108 + assert _annotation({"description": "free form"}) is t.Any