Skip to content

Commit 5177982

Browse files
committed
build(deps): bump com.networknt:json-schema-validator from 1.0.87 to 1.4.3
1 parent adbd750 commit 5177982

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

powertools-validation/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<dependency>
6666
<groupId>com.networknt</groupId>
6767
<artifactId>json-schema-validator</artifactId>
68-
<version>1.0.87</version>
68+
<version>1.4.3</version>
6969
</dependency>
7070
<dependency>
7171
<groupId>com.amazonaws</groupId>

powertools-validation/src/main/java/software/amazon/lambda/powertools/validation/ValidationUtils.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121
import com.fasterxml.jackson.databind.node.JsonNodeType;
2222
import com.fasterxml.jackson.databind.node.NullNode;
2323
import com.networknt.schema.JsonSchema;
24+
import com.networknt.schema.SchemaLocation;
2425
import com.networknt.schema.SchemaValidatorsConfig;
2526
import com.networknt.schema.ValidationMessage;
26-
import com.networknt.schema.uri.URITranslator;
2727
import io.burt.jmespath.Expression;
2828
import java.io.ByteArrayOutputStream;
29-
import java.io.InputStream;
3029
import java.util.Collections;
3130
import java.util.Map;
3231
import java.util.Set;
3332
import java.util.concurrent.ConcurrentHashMap;
3433
import java.util.stream.Collectors;
35-
import software.amazon.lambda.powertools.validation.internal.ValidationAspect;
3634

3735
/**
3836
* Validation utility, used to manually validate Json against Json Schema
@@ -255,27 +253,26 @@ public static JsonSchema getJsonSchema(String schema, boolean validateSchema) {
255253

256254
private static JsonSchema createJsonSchema(String schema) {
257255
JsonSchema jsonSchema;
256+
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().formatAssertionsEnabled(true)
257+
.preloadJsonSchemaRefMaxNestingDepth(10).build();
258258
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);
266261
} catch (Exception e) {
262+
String filePath = schema.substring(CLASSPATH.length());
267263
throw new IllegalArgumentException(
268-
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath");
264+
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath", e);
269265
}
270266
} else {
271-
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema);
267+
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema, config);
272268
}
273269

274270
return jsonSchema;
275271
}
276272

277273
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", "");
279276
try {
280277
validate(jsonSchema.getSchemaNode(),
281278
getJsonSchema(CLASSPATH + schemaId));

powertools-validation/src/test/java/software/amazon/lambda/powertools/validation/ValidationUtilsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void testLoadSchemaV7OK() {
4848
ValidationConfig.get().setSchemaVersion(SpecVersion.VersionFlag.V7);
4949
JsonSchema jsonSchema = getJsonSchema("classpath:/schema_v7.json", true);
5050
assertThat(jsonSchema).isNotNull();
51-
assertThat(jsonSchema.getCurrentUri()).asString().isEqualTo("http://example.com/product.json");
51+
assertThat(jsonSchema.getId()).isEqualTo("http://example.com/product.json");
5252
}
5353

5454
@Test
@@ -57,7 +57,7 @@ public void testLoadSchemaV7KO() {
5757
assertThatThrownBy(() -> getJsonSchema("classpath:/schema_v7_ko.json", true))
5858
.isInstanceOf(IllegalArgumentException.class)
5959
.hasMessage(
60-
"The schema classpath:/schema_v7_ko.json is not valid, it does not respect the specification /draft-07/schema");
60+
"The schema classpath:/schema_v7_ko.json is not valid, it does not respect the specification /draft-07/schema#");
6161
}
6262

6363
@Test

powertools-validation/src/test/resources/schema_v7.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema",
2+
"$schema": "http://json-schema.org/draft-07/schema#",
33
"$id": "http://example.com/product.json",
44
"type": "object",
55
"title": "Product schema",

powertools-validation/src/test/resources/schema_v7_ko.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema",
2+
"$schema": "http://json-schema.org/draft-07/schema#",
33
"type": "object",
44
"title": "Product schema",
55
"description": "JSON schema to validate Products",

0 commit comments

Comments
 (0)