Skip to content

chore: Extract shouldIgnoredInJsonSchema method in JsonSchemaGenerator #3062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -128,12 +128,7 @@ public static String generateForMethodInput(Method method, SchemaOption... schem
for (int i = 0; i < method.getParameterCount(); i++) {
String parameterName = method.getParameters()[i].getName();
Type parameterType = method.getGenericParameterTypes()[i];
if (parameterType instanceof Class<?> parameterClass
&& ClassUtils.isAssignable(parameterClass, ToolContext.class)) {
// 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
// outside the model interaction flow.
if (shouldIgnoredInJsonSchema(parameterType)) {
continue;
}
if (isMethodParameterRequired(method, i)) {
Expand All @@ -155,6 +150,15 @@ public static String generateForMethodInput(Method method, SchemaOption... schem
return schema.toPrettyString();
}

private static boolean shouldIgnoredInJsonSchema(final Type parameterType) {
// 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
// outside the model interaction flow.
return parameterType instanceof Class<?> parameterClass
&& ClassUtils.isAssignable(parameterClass, ToolContext.class);
}

/**
* Generate a JSON Schema for a class type.
*/
Expand Down