@@ -239,12 +239,17 @@ public static JsonSchema getJsonSchema(String schema) {
239
239
* @return the loaded json schema
240
240
*/
241
241
public static JsonSchema getJsonSchema (String schema , boolean validateSchema ) {
242
- JsonSchema jsonSchema = schemas .get (schema );
242
+ JsonSchema jsonSchema = schemas .computeIfAbsent (schema , ValidationUtils :: createJsonSchema );
243
243
244
- if (jsonSchema != null ) {
245
- return jsonSchema ;
244
+ if (validateSchema ) {
245
+ validateSchema ( schema , jsonSchema ) ;
246
246
}
247
247
248
+ return jsonSchema ;
249
+ }
250
+
251
+ private static JsonSchema createJsonSchema (String schema ) {
252
+ JsonSchema jsonSchema ;
248
253
if (schema .startsWith (CLASSPATH )) {
249
254
String filePath = schema .substring (CLASSPATH .length ());
250
255
try (InputStream schemaStream = ValidationAspect .class .getResourceAsStream (filePath )) {
@@ -260,21 +265,19 @@ public static JsonSchema getJsonSchema(String schema, boolean validateSchema) {
260
265
jsonSchema = ValidationConfig .get ().getFactory ().getSchema (schema );
261
266
}
262
267
263
- if (validateSchema ) {
264
- String version = ValidationConfig .get ().getSchemaVersion ().toString ();
265
- try {
266
- validate (jsonSchema .getSchemaNode (),
267
- getJsonSchema ("classpath:/schemas/meta_schema_" + version ));
268
- } catch (ValidationException ve ) {
269
- throw new IllegalArgumentException ("The schema " + schema + " is not valid, it does not respect the specification " + version , ve );
270
- }
271
- }
272
-
273
- schemas .put (schema , jsonSchema );
274
-
275
268
return jsonSchema ;
276
269
}
277
270
271
+ private static void validateSchema (String schema , JsonSchema jsonSchema ) {
272
+ String version = ValidationConfig .get ().getSchemaVersion ().toString ();
273
+ try {
274
+ validate (jsonSchema .getSchemaNode (),
275
+ getJsonSchema ("classpath:/schemas/meta_schema_" + version ));
276
+ } catch (ValidationException ve ) {
277
+ throw new IllegalArgumentException ("The schema " + schema + " is not valid, it does not respect the specification " + version , ve );
278
+ }
279
+ }
280
+
278
281
/**
279
282
*
280
283
*/
0 commit comments