From 195302446d3322c03efd68afdb95fc7e0b0cd68a Mon Sep 17 00:00:00 2001 From: TheEterna <125226601+TheEterna@users.noreply.github.com> Date: Thu, 3 Jul 2025 01:53:05 +0800 Subject: [PATCH 1/2] Fix the judge bug Signed-off-by: TheEterna <125226601+TheEterna@users.noreply.github.com> --- .../ai/util/json/schema/JsonSchemaGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-ai-model/src/main/java/org/springframework/ai/util/json/schema/JsonSchemaGenerator.java b/spring-ai-model/src/main/java/org/springframework/ai/util/json/schema/JsonSchemaGenerator.java index 27fae0fcc55..c66b9af2733 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/util/json/schema/JsonSchemaGenerator.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/util/json/schema/JsonSchemaGenerator.java @@ -129,7 +129,7 @@ public static String generateForMethodInput(Method method, SchemaOption... schem String parameterName = method.getParameters()[i].getName(); Type parameterType = method.getGenericParameterTypes()[i]; if (parameterType instanceof Class parameterClass - && ClassUtils.isAssignable(parameterClass, ToolContext.class)) { + && ClassUtils.isAssignable(ToolContext.class, parameterClass)) { // A ToolContext method parameter is not included in the JSON Schema // generation. // It's a special type used by Spring AI to pass contextual data to tools From 99530845666eb8b363090330bbaf0b1390bcec9c Mon Sep 17 00:00:00 2001 From: TheEterna <125226601+TheEterna@users.noreply.github.com> Date: Thu, 3 Jul 2025 10:35:46 +0800 Subject: [PATCH 2/2] Add unit testing Signed-off-by: TheEterna <125226601+TheEterna@users.noreply.github.com> --- .../util/json/JsonSchemaGeneratorTests.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spring-ai-model/src/test/java/org/springframework/ai/util/json/JsonSchemaGeneratorTests.java b/spring-ai-model/src/test/java/org/springframework/ai/util/json/JsonSchemaGeneratorTests.java index c0c61f7eab6..243ec73bbfb 100644 --- a/spring-ai-model/src/test/java/org/springframework/ai/util/json/JsonSchemaGeneratorTests.java +++ b/spring-ai-model/src/test/java/org/springframework/ai/util/json/JsonSchemaGeneratorTests.java @@ -161,6 +161,29 @@ void generateSchemaForMethodWithOpenApiSchemaAnnotations() throws Exception { assertThat(schema).isEqualToIgnoringWhitespace(expectedJsonSchema); } + @Test + void generateSchemaForMethodWithObjectParam() throws Exception { + Method method = TestMethods.class.getDeclaredMethod("objectParamMethod", Object.class); + + String schema = JsonSchemaGenerator.generateForMethodInput(method); + String expectedJsonSchema = """ + { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "object": { + } + }, + "required": [ + "object" + ], + "additionalProperties": false + } + """; + + assertThat(schema).isEqualToIgnoringWhitespace(expectedJsonSchema); + } + @Test void generateSchemaForMethodWithJacksonAnnotations() throws Exception { Method method = TestMethods.class.getDeclaredMethod("jacksonMethod", String.class, String.class); @@ -662,6 +685,9 @@ static class TestMethods { public void simpleMethod(String name, int age) { } + public void objectParamMethod(Object object) { + } + public void annotatedMethod( @ToolParam(required = false, description = "The username of the customer") String username, @ToolParam(required = true) String password) {