Skip to content

Commit ed85f7e

Browse files
authored
Bump json-schema-validator from 1.5.7 to 2.0.0 (#660)
1 parent 476f9db commit ed85f7e

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson/DefaultJsonSchemaValidator.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
*/
44
package io.modelcontextprotocol.json.schema.jackson;
55

6+
import java.util.List;
67
import java.util.Map;
7-
import java.util.Set;
88
import java.util.concurrent.ConcurrentHashMap;
99

1010
import com.fasterxml.jackson.core.JsonProcessingException;
1111
import com.fasterxml.jackson.databind.JsonNode;
1212
import 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;
1717
import io.modelcontextprotocol.json.schema.JsonSchemaValidator;
1818
import org.slf4j.Logger;
1919
import 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);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<awaitility.version>4.2.0</awaitility.version>
9797
<bnd-maven-plugin.version>7.1.0</bnd-maven-plugin.version>
9898
<json-unit-assertj.version>4.1.0</json-unit-assertj.version>
99-
<json-schema-validator.version>1.5.7</json-schema-validator.version>
99+
<json-schema-validator.version>2.0.0</json-schema-validator.version>
100100

101101
</properties>
102102

0 commit comments

Comments
 (0)