|
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.SchemaLocation; |
24 | 25 | import com.networknt.schema.SchemaValidatorsConfig;
|
25 | 26 | import com.networknt.schema.ValidationMessage;
|
26 |
| -import com.networknt.schema.uri.URITranslator; |
27 | 27 | import io.burt.jmespath.Expression;
|
28 | 28 | import java.io.ByteArrayOutputStream;
|
29 |
| -import java.io.InputStream; |
30 | 29 | import java.util.Collections;
|
31 | 30 | import java.util.Map;
|
32 | 31 | import java.util.Set;
|
33 | 32 | import java.util.concurrent.ConcurrentHashMap;
|
34 | 33 | import java.util.stream.Collectors;
|
35 |
| -import software.amazon.lambda.powertools.validation.internal.ValidationAspect; |
36 | 34 |
|
37 | 35 | /**
|
38 | 36 | * Validation utility, used to manually validate Json against Json Schema
|
@@ -255,27 +253,26 @@ public static JsonSchema getJsonSchema(String schema, boolean validateSchema) {
|
255 | 253 |
|
256 | 254 | private static JsonSchema createJsonSchema(String schema) {
|
257 | 255 | JsonSchema jsonSchema;
|
| 256 | + SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().formatAssertionsEnabled(true) |
| 257 | + .preloadJsonSchemaRefMaxNestingDepth(10).build(); |
258 | 258 | if (schema.startsWith(CLASSPATH)) {
|
259 |
| - String filePath = schema.substring(CLASSPATH.length()); |
260 |
| - try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) { |
261 |
| - |
262 |
| - SchemaValidatorsConfig config = new SchemaValidatorsConfig(); |
263 |
| - config.addUriTranslator(URITranslator.prefix("https://json-schema.org", "resource:")); |
264 |
| - |
265 |
| - jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream, config); |
| 259 | + try { |
| 260 | + jsonSchema = ValidationConfig.get().getFactory().getSchema(SchemaLocation.of(schema), config); |
266 | 261 | } catch (Exception e) {
|
| 262 | + String filePath = schema.substring(CLASSPATH.length()); |
267 | 263 | throw new IllegalArgumentException(
|
268 |
| - "'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath"); |
| 264 | + "'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath", e); |
269 | 265 | }
|
270 | 266 | } else {
|
271 |
| - jsonSchema = ValidationConfig.get().getFactory().getSchema(schema); |
| 267 | + jsonSchema = ValidationConfig.get().getFactory().getSchema(schema, config); |
272 | 268 | }
|
273 | 269 |
|
274 | 270 | return jsonSchema;
|
275 | 271 | }
|
276 | 272 |
|
277 | 273 | private static void validateSchema(String schema, JsonSchema jsonSchema) {
|
278 |
| - String schemaId = ValidationConfig.get().getSchemaVersion().getId().replace("https://json-schema.org", ""); |
| 274 | + String schemaId = jsonSchema.getValidationContext().getMetaSchema().getIri() |
| 275 | + .replace("https://json-schema.org", "").replace("http://json-schema.org", ""); |
279 | 276 | try {
|
280 | 277 | validate(jsonSchema.getSchemaNode(),
|
281 | 278 | getJsonSchema(CLASSPATH + schemaId));
|
|
0 commit comments