21
21
import com .fasterxml .jackson .databind .node .JsonNodeType ;
22
22
import com .fasterxml .jackson .databind .node .NullNode ;
23
23
import com .networknt .schema .JsonSchema ;
24
+ import com .networknt .schema .SchemaValidatorsConfig ;
24
25
import com .networknt .schema .ValidationMessage ;
26
+ import com .networknt .schema .uri .URITranslator ;
25
27
import io .burt .jmespath .Expression ;
26
28
import java .io .ByteArrayOutputStream ;
27
29
import java .io .InputStream ;
@@ -257,7 +259,10 @@ private static JsonSchema createJsonSchema(String schema) {
257
259
String filePath = schema .substring (CLASSPATH .length ());
258
260
try (InputStream schemaStream = ValidationAspect .class .getResourceAsStream (filePath )) {
259
261
260
- jsonSchema = ValidationConfig .get ().getFactory ().getSchema (schemaStream );
262
+ SchemaValidatorsConfig config = new SchemaValidatorsConfig ();
263
+ config .addUriTranslator (URITranslator .prefix ("https://json-schema.org" , "resource:" ));
264
+
265
+ jsonSchema = ValidationConfig .get ().getFactory ().getSchema (schemaStream , config );
261
266
} catch (Exception e ) {
262
267
throw new IllegalArgumentException (
263
268
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath" );
@@ -270,13 +275,13 @@ private static JsonSchema createJsonSchema(String schema) {
270
275
}
271
276
272
277
private static void validateSchema (String schema , JsonSchema jsonSchema ) {
273
- String version = ValidationConfig .get ().getSchemaVersion ().toString ( );
278
+ String schemaId = ValidationConfig .get ().getSchemaVersion ().getId (). replace ( "https://json-schema.org" , "" );
274
279
try {
275
280
validate (jsonSchema .getSchemaNode (),
276
- getJsonSchema ("classpath:/schemas/meta_schema_" + version ));
281
+ getJsonSchema (CLASSPATH + schemaId ));
277
282
} catch (ValidationException ve ) {
278
283
throw new IllegalArgumentException (
279
- "The schema " + schema + " is not valid, it does not respect the specification " + version , ve );
284
+ "The schema " + schema + " is not valid, it does not respect the specification " + schemaId , ve );
280
285
}
281
286
}
282
287
0 commit comments