Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down