diff --git a/src/neuroconv/utils/json_schema.py b/src/neuroconv/utils/json_schema.py index 6aa7a75d0..a7e6e0518 100644 --- a/src/neuroconv/utils/json_schema.py +++ b/src/neuroconv/utils/json_schema.py @@ -140,7 +140,8 @@ def get_json_schema_from_method_signature(method: Callable, exclude: Optional[li additional_properties = True continue - annotation = parameter.annotation + # If no annotation is provided (inspect._empty), use Any instead + annotation = Any if parameter.annotation is inspect._empty else parameter.annotation # Pydantic uses ellipsis for required pydantic_default = ... if parameter.default is inspect._empty else parameter.default diff --git a/tests/test_minimal/test_utils/test_get_json_schema_from_method_signature.py b/tests/test_minimal/test_utils/test_get_json_schema_from_method_signature.py index e6fe27e16..c2cea1d75 100644 --- a/tests/test_minimal/test_utils/test_get_json_schema_from_method_signature.py +++ b/tests/test_minimal/test_utils/test_get_json_schema_from_method_signature.py @@ -424,3 +424,26 @@ def test_class_method(self, integer: int): } assert test_json_schema == expected_json_schema + + +def test_get_json_schema_from_method_signature_unannotated(): + """Test that parameters without type annotations are handled correctly by defaulting to Any.""" + + def method_with_unannotated_params( + annotated_param: int, unannotated_param, unannotated_with_default="default_value" + ): + pass + + test_json_schema = get_json_schema_from_method_signature(method=method_with_unannotated_params) + expected_json_schema = { + "additionalProperties": False, + "properties": { + "annotated_param": {"type": "integer"}, + "unannotated_param": {}, # Any type in JSON Schema is represented by an empty object + "unannotated_with_default": {"default": "default_value"}, + }, + "required": ["annotated_param", "unannotated_param"], + "type": "object", + } + + assert test_json_schema == expected_json_schema