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 @@ -184,15 +184,7 @@ public static String generateFromClass(Class<?> clazz) {
}

private static String internalGenerateFromClass(Class<?> clazz) {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12,
OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.without(Option.FLATTENED_ENUMS_FROM_TOSTRING)
.build();

SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonSchema = generator.generateSchema(clazz);
return jsonSchema.toPrettyString();
return TYPE_SCHEMA_GENERATOR.generateSchema(clazz).toPrettyString();
}

public static String generateFromType(Type type) {
Expand All @@ -201,15 +193,7 @@ public static String generateFromType(Type type) {
}

private static String internalGenerateFromType(Type type) {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12,
OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.without(Option.FLATTENED_ENUMS_FROM_TOSTRING)
.build();

SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonSchema = generator.generateSchema(type);
return jsonSchema.toPrettyString();
return TYPE_SCHEMA_GENERATOR.generateSchema(type).toPrettyString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Map;
import java.util.function.BiFunction;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import org.junit.jupiter.api.Test;
import org.springaicommunity.mcp.annotation.McpTool;

Expand Down Expand Up @@ -586,7 +588,9 @@ public String defaultAnnotationsTool(String input) {
void testToolWithOutputSchemaGeneration() {

// Define a custom result class
record CustomResult(String message, int count) {
record CustomResult(@JsonPropertyDescription("customResultMessage") @JsonProperty(required = false)
String message,
@JsonProperty(required = true) int count) {
}

class OutputSchemaTool {
Expand All @@ -613,7 +617,7 @@ public List<CustomResult> outputSchemaTool(String input) {
assertThat(outputSchemaString).contains("message");
assertThat(outputSchemaString).contains("count");
assertThat(outputSchemaString).isEqualTo(
"{$schema=https://json-schema.org/draft/2020-12/schema, type=array, items={type=object, properties={count={type=integer, format=int32}, message={type=string}}}}");
"{$schema=https://json-schema.org/draft/2020-12/schema, type=array, items={type=object, properties={count={type=integer, format=int32}, message={type=string, description=customResultMessage}}, required=[count]}}");
}

@Test
Expand Down