Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.5.9</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/spdx/tools/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.ValidationMessage;
import com.networknt.schema.Schema;
import com.networknt.schema.SchemaRegistry;
import com.networknt.schema.SpecificationVersion;
import com.networknt.schema.Error;

/**
* Verifies an SPDX document and lists any verification errors
Expand Down Expand Up @@ -172,17 +172,18 @@ public static List<String> verify(String filePath, SerFileType fileType) throws
} else {
jsonSchemaResource = JSON_SCHEMA_RESOURCE_V3;
}
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
JsonSchema schema;
SchemaRegistry schemaRegistry =
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
Schema schema;
try (InputStream is = Verify.class.getResourceAsStream("/" + jsonSchemaResource)) {
schema = jsonSchemaFactory.getSchema(is);
schema = schemaRegistry.getSchema(is);
}
JsonNode root;
try (InputStream is = new FileInputStream(file)) {
root = JSON_MAPPER.readTree(is);
}
Set<ValidationMessage> messages = schema.validate(root);
for (ValidationMessage msg:messages) {
List<Error> messages = schema.validate(root);
for (Error msg:messages) {
retval.add(msg.toString());
}
} catch (IOException e) {
Expand Down