33 */
44package io .modelcontextprotocol .json .schema .jackson ;
55
6+ import java .util .List ;
67import java .util .Map ;
7- import java .util .Set ;
88import java .util .concurrent .ConcurrentHashMap ;
99
1010import com .fasterxml .jackson .core .JsonProcessingException ;
1111import com .fasterxml .jackson .databind .JsonNode ;
1212import com .fasterxml .jackson .databind .ObjectMapper ;
13- import com .networknt .schema .JsonSchema ;
14- import com .networknt .schema .JsonSchemaFactory ;
15- import com .networknt .schema .SpecVersion ;
16- import com .networknt .schema .ValidationMessage ;
13+ import com .networknt .schema .Schema ;
14+ import com .networknt .schema .SchemaRegistry ;
15+ import com .networknt .schema .Error ;
16+ import com .networknt .schema .dialect . Dialects ;
1717import io .modelcontextprotocol .json .schema .JsonSchemaValidator ;
1818import org .slf4j .Logger ;
1919import org .slf4j .LoggerFactory ;
@@ -31,18 +31,18 @@ public class DefaultJsonSchemaValidator implements JsonSchemaValidator {
3131
3232 private final ObjectMapper objectMapper ;
3333
34- private final JsonSchemaFactory schemaFactory ;
34+ private final SchemaRegistry schemaFactory ;
3535
3636 // TODO: Implement a strategy to purge the cache (TTL, size limit, etc.)
37- private final ConcurrentHashMap <String , JsonSchema > schemaCache ;
37+ private final ConcurrentHashMap <String , Schema > schemaCache ;
3838
3939 public DefaultJsonSchemaValidator () {
4040 this (new ObjectMapper ());
4141 }
4242
4343 public DefaultJsonSchemaValidator (ObjectMapper objectMapper ) {
4444 this .objectMapper = objectMapper ;
45- this .schemaFactory = JsonSchemaFactory . getInstance ( SpecVersion . VersionFlag . V202012 );
45+ this .schemaFactory = SchemaRegistry . withDialect ( Dialects . getDraft202012 () );
4646 this .schemaCache = new ConcurrentHashMap <>();
4747 }
4848
@@ -62,7 +62,7 @@ public ValidationResponse validate(Map<String, Object> schema, Object structured
6262 ? this .objectMapper .readTree ((String ) structuredContent )
6363 : this .objectMapper .valueToTree (structuredContent );
6464
65- Set < ValidationMessage > validationResult = this .getOrCreateJsonSchema (schema ).validate (jsonStructuredOutput );
65+ List < Error > validationResult = this .getOrCreateJsonSchema (schema ).validate (jsonStructuredOutput );
6666
6767 // Check if validation passed
6868 if (!validationResult .isEmpty ()) {
@@ -85,36 +85,36 @@ public ValidationResponse validate(Map<String, Object> schema, Object structured
8585 }
8686
8787 /**
88- * Gets a cached JsonSchema or creates and caches a new one.
88+ * Gets a cached Schema or creates and caches a new one.
8989 * @param schema the schema map to convert
90- * @return the compiled JsonSchema
90+ * @return the compiled Schema
9191 * @throws JsonProcessingException if schema processing fails
9292 */
93- private JsonSchema getOrCreateJsonSchema (Map <String , Object > schema ) throws JsonProcessingException {
93+ private Schema getOrCreateJsonSchema (Map <String , Object > schema ) throws JsonProcessingException {
9494 // Generate cache key based on schema content
9595 String cacheKey = this .generateCacheKey (schema );
9696
9797 // Try to get from cache first
98- JsonSchema cachedSchema = this .schemaCache .get (cacheKey );
98+ Schema cachedSchema = this .schemaCache .get (cacheKey );
9999 if (cachedSchema != null ) {
100100 return cachedSchema ;
101101 }
102102
103103 // Create new schema if not in cache
104- JsonSchema newSchema = this .createJsonSchema (schema );
104+ Schema newSchema = this .createJsonSchema (schema );
105105
106106 // Cache the schema
107- JsonSchema existingSchema = this .schemaCache .putIfAbsent (cacheKey , newSchema );
107+ Schema existingSchema = this .schemaCache .putIfAbsent (cacheKey , newSchema );
108108 return existingSchema != null ? existingSchema : newSchema ;
109109 }
110110
111111 /**
112- * Creates a new JsonSchema from the given schema map.
112+ * Creates a new Schema from the given schema map.
113113 * @param schema the schema map
114- * @return the compiled JsonSchema
114+ * @return the compiled Schema
115115 * @throws JsonProcessingException if schema processing fails
116116 */
117- private JsonSchema createJsonSchema (Map <String , Object > schema ) throws JsonProcessingException {
117+ private Schema createJsonSchema (Map <String , Object > schema ) throws JsonProcessingException {
118118 // Convert schema map directly to JsonNode (more efficient than string
119119 // serialization)
120120 JsonNode schemaNode = this .objectMapper .valueToTree (schema );
0 commit comments