Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump com.networknt:json-schema-validator from 1.0.87 to 1.4.3 #1674

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion powertools-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.0.87</version>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.NullNode;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.SchemaLocation;
import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.schema.ValidationMessage;
import com.networknt.schema.uri.URITranslator;
import io.burt.jmespath.Expression;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import software.amazon.lambda.powertools.validation.internal.ValidationAspect;

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

private static JsonSchema createJsonSchema(String schema) {
JsonSchema jsonSchema;
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().formatAssertionsEnabled(true)
.preloadJsonSchemaRefMaxNestingDepth(10).build();
jeromevdl marked this conversation as resolved.
Show resolved Hide resolved
if (schema.startsWith(CLASSPATH)) {
String filePath = schema.substring(CLASSPATH.length());
try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) {

SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.addUriTranslator(URITranslator.prefix("https://json-schema.org", "resource:"));

jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream, config);
try {
jsonSchema = ValidationConfig.get().getFactory().getSchema(SchemaLocation.of(schema), config);
} catch (Exception e) {
String filePath = schema.substring(CLASSPATH.length());
throw new IllegalArgumentException(
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath");
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath", e);
}
} else {
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema);
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema, config);
}

return jsonSchema;
}

private static void validateSchema(String schema, JsonSchema jsonSchema) {
String schemaId = ValidationConfig.get().getSchemaVersion().getId().replace("https://json-schema.org", "");
String schemaId = jsonSchema.getValidationContext().getMetaSchema().getIri()
.replace("https://json-schema.org", "").replace("http://json-schema.org", "");
try {
validate(jsonSchema.getSchemaNode(),
getJsonSchema(CLASSPATH + schemaId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testLoadSchemaV7OK() {
ValidationConfig.get().setSchemaVersion(SpecVersion.VersionFlag.V7);
JsonSchema jsonSchema = getJsonSchema("classpath:/schema_v7.json", true);
assertThat(jsonSchema).isNotNull();
assertThat(jsonSchema.getCurrentUri()).asString().isEqualTo("http://example.com/product.json");
assertThat(jsonSchema.getId()).isEqualTo("http://example.com/product.json");
}

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

@Test
Expand Down
2 changes: 1 addition & 1 deletion powertools-validation/src/test/resources/schema_v7.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",
jeromevdl marked this conversation as resolved.
Show resolved Hide resolved
"$id": "http://example.com/product.json",
"type": "object",
"title": "Product schema",
Expand Down
2 changes: 1 addition & 1 deletion powertools-validation/src/test/resources/schema_v7_ko.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Product schema",
"description": "JSON schema to validate Products",
Expand Down
Loading