Skip to content

Commit 919c27a

Browse files
committed
Refine meta-schema loading and deprecate orphan JsonSchemaValidator
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
1 parent 57c5a10 commit 919c27a

3 files changed

Lines changed: 8 additions & 38 deletions

File tree

mcp-core/src/main/java/io/modelcontextprotocol/spec/JsonSchemaValidator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
* defines a method to validate structured content based on the provided output schema.
1212
*
1313
* @author Christian Tzolov
14+
* @deprecated Use {@link io.modelcontextprotocol.json.schema.JsonSchemaValidator}
1415
*/
16+
@Deprecated
1517
public interface JsonSchemaValidator {
1618

1719
/**

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

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

6-
import java.io.IOException;
7-
import java.io.InputStream;
86
import java.util.List;
97
import java.util.Map;
108
import java.util.concurrent.ConcurrentHashMap;
119

10+
import com.networknt.schema.SchemaLocation;
1211
import io.modelcontextprotocol.util.Assert;
1312
import org.slf4j.Logger;
1413
import org.slf4j.LoggerFactory;
@@ -52,23 +51,8 @@ public DefaultJsonSchemaValidator(ObjectMapper objectMapper) {
5251
this.objectMapper = objectMapper;
5352
this.schemaFactory = SchemaRegistry.withDefaultDialect(Dialects.getDraft202012());
5453
this.schemaCache = new ConcurrentHashMap<>();
55-
this.metaSchema202012 = loadMetaSchema();
56-
}
57-
58-
private Schema loadMetaSchema() {
59-
try (InputStream stream = getClass().getClassLoader().getResourceAsStream("draft/2020-12/schema")) {
60-
if (stream == null) {
61-
logger.warn(
62-
"JSON Schema 2020-12 meta-schema not found on classpath; schema conformance checking disabled");
63-
return null;
64-
}
65-
return this.schemaFactory.getSchema(stream);
66-
}
67-
catch (IOException e) {
68-
logger.warn("Failed to load JSON Schema 2020-12 meta-schema: {}; schema conformance checking disabled",
69-
e.getMessage());
70-
return null;
71-
}
54+
this.metaSchema202012 = schemaFactory
55+
.getSchema(SchemaLocation.of("https://json-schema.org/draft/2020-12/schema"));
7256
}
7357

7458
@Override

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

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

6-
import java.io.IOException;
7-
import java.io.InputStream;
86
import java.util.List;
97
import java.util.Map;
108
import java.util.concurrent.ConcurrentHashMap;
119

1210
import com.networknt.schema.Schema;
11+
import com.networknt.schema.SchemaLocation;
1312
import com.networknt.schema.SchemaRegistry;
1413
import com.networknt.schema.Error;
1514
import com.networknt.schema.dialect.Dialects;
@@ -51,23 +50,8 @@ public DefaultJsonSchemaValidator(JsonMapper jsonMapper) {
5150
this.jsonMapper = jsonMapper;
5251
this.schemaFactory = SchemaRegistry.withDefaultDialect(Dialects.getDraft202012());
5352
this.schemaCache = new ConcurrentHashMap<>();
54-
this.metaSchema202012 = loadMetaSchema();
55-
}
56-
57-
private Schema loadMetaSchema() {
58-
try (InputStream stream = getClass().getClassLoader().getResourceAsStream("draft/2020-12/schema")) {
59-
if (stream == null) {
60-
logger.warn(
61-
"JSON Schema 2020-12 meta-schema not found on classpath; schema conformance checking disabled");
62-
return null;
63-
}
64-
return this.schemaFactory.getSchema(stream);
65-
}
66-
catch (IOException e) {
67-
logger.warn("Failed to load JSON Schema 2020-12 meta-schema: {}; schema conformance checking disabled",
68-
e.getMessage());
69-
return null;
70-
}
53+
this.metaSchema202012 = schemaFactory
54+
.getSchema(SchemaLocation.of("https://json-schema.org/draft/2020-12/schema"));
7155
}
7256

7357
@Override

0 commit comments

Comments
 (0)