Skip to content

Commit 77a41de

Browse files
committed
Revert json-schema-validator version to 1.5.9
Fixes #257 Version 2.0.0 of the json-schema-validator introduces a very significant performance degredation Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent de4734d commit 77a41de

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

examples/org/spdx/examples/ExpandedLicenseExampleV3.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-FileCopyrightText: Copyright (c) 2025 Source Auditor Inc.
44
* SPDX-FileType: SOURCE
55
* SPDX-License-Identifier: Apache-2.0
6-
*
6+
* <br/>
77
* Example of serializing a single expanded license
88
*/
99

@@ -12,10 +12,10 @@
1212
import com.fasterxml.jackson.databind.JsonNode;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
1414
import com.fasterxml.jackson.databind.SerializationFeature;
15-
import com.networknt.schema.Error;
16-
import com.networknt.schema.Schema;
17-
import com.networknt.schema.SchemaRegistry;
18-
import com.networknt.schema.SpecificationVersion;
15+
import com.networknt.schema.JsonSchema;
16+
import com.networknt.schema.JsonSchemaFactory;
17+
import com.networknt.schema.SpecVersion.VersionFlag;
18+
import com.networknt.schema.ValidationMessage;
1919
import org.spdx.core.DefaultModelStore;
2020
import org.spdx.core.IModelCopyManager;
2121
import org.spdx.library.LicenseInfoFactory;
@@ -37,6 +37,7 @@
3737
import java.util.ArrayList;
3838
import java.util.Collection;
3939
import java.util.List;
40+
import java.util.Set;
4041

4142
import static org.spdx.tools.Verify.JSON_SCHEMA_RESOURCE_V3;
4243

@@ -158,18 +159,17 @@ public static void main(String[] args) throws Exception {
158159
try (OutputStream outStream = new FileOutputStream(outFile)) {
159160
modelStore.serialize(outStream, doc);
160161
}
161-
SchemaRegistry schemaRegistry =
162-
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
163-
Schema schema;
162+
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
163+
JsonSchema schema;
164164
try (InputStream is = Verify.class.getResourceAsStream("/" + JSON_SCHEMA_RESOURCE_V3)) {
165-
schema = schemaRegistry.getSchema(is);
165+
schema = jsonSchemaFactory.getSchema(is);
166166
}
167167
JsonNode root;
168168
try (InputStream is = new FileInputStream(outFile)) {
169169
root = JSON_MAPPER.readTree(is);
170170
}
171-
List<com.networknt.schema.Error> messages = schema.validate(root);
172-
for (Error msg:messages) {
171+
Set<ValidationMessage> messages = schema.validate(root);
172+
for (ValidationMessage msg:messages) {
173173
warnings.add(msg.toString());
174174
}
175175
if (!warnings.isEmpty()) {

examples/org/spdx/examples/FullSpdxV3Example.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-FileCopyrightText: Copyright (c) 2025 Source Auditor Inc.
44
* SPDX-FileType: SOURCE
55
* SPDX-License-Identifier: Apache-2.0
6-
*
6+
* <br/>
77
* Full example of an SPDX document using all classes
88
*/
99

@@ -12,10 +12,10 @@
1212
import com.fasterxml.jackson.databind.JsonNode;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
1414
import com.fasterxml.jackson.databind.SerializationFeature;
15-
import com.networknt.schema.Error;
16-
import com.networknt.schema.Schema;
17-
import com.networknt.schema.SchemaRegistry;
18-
import com.networknt.schema.SpecificationVersion;
15+
import com.networknt.schema.JsonSchema;
16+
import com.networknt.schema.JsonSchemaFactory;
17+
import com.networknt.schema.SpecVersion.VersionFlag;
18+
import com.networknt.schema.ValidationMessage;
1919
import org.spdx.core.DefaultModelStore;
2020
import org.spdx.core.IModelCopyManager;
2121
import org.spdx.core.InvalidSPDXAnalysisException;
@@ -838,18 +838,17 @@ public static void main(String[] args) throws Exception {
838838
}
839839

840840
// Validate using the schema
841-
SchemaRegistry schemaRegistry =
842-
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
843-
Schema schema;
841+
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
842+
JsonSchema schema;
844843
try (InputStream is = Verify.class.getResourceAsStream("/" + JSON_SCHEMA_RESOURCE_V3)) {
845-
schema = schemaRegistry.getSchema(is);
844+
schema = jsonSchemaFactory.getSchema(is);
846845
}
847846
JsonNode root;
848847
try (InputStream is = new FileInputStream(outFile)) {
849848
root = JSON_MAPPER.readTree(is);
850849
}
851-
List<Error> messages = schema.validate(root);
852-
for (Error msg:messages) {
850+
Set<ValidationMessage> messages = schema.validate(root);
851+
for (ValidationMessage msg:messages) {
853852
warnings.add(msg.toString());
854853
}
855854
if (!warnings.isEmpty()) {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<dependency>
149149
<groupId>com.networknt</groupId>
150150
<artifactId>json-schema-validator</artifactId>
151-
<version>2.0.0</version>
151+
<version>1.5.9</version>
152152
</dependency>
153153
<dependency>
154154
<groupId>org.slf4j</groupId>

src/main/java/org/spdx/tools/Verify.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* SPDX-FileCopyrightText: Copyright (c) 2015 Source Auditor Inc.
33
* SPDX-FileType: SOURCE
44
* SPDX-License-Identifier: Apache-2.0
5-
*
5+
* <br/>
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
* <br/>
1010
* https://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
* <br/>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,6 +26,7 @@
2626
import java.util.ArrayList;
2727
import java.util.List;
2828
import java.util.Objects;
29+
import java.util.Set;
2930

3031
import com.fasterxml.jackson.core.JsonParseException;
3132

@@ -39,10 +40,11 @@
3940
import com.fasterxml.jackson.databind.JsonNode;
4041
import com.fasterxml.jackson.databind.ObjectMapper;
4142
import com.fasterxml.jackson.databind.SerializationFeature;
42-
import com.networknt.schema.Schema;
43-
import com.networknt.schema.SchemaRegistry;
44-
import com.networknt.schema.SpecificationVersion;
45-
import com.networknt.schema.Error;
43+
44+
import com.networknt.schema.JsonSchema;
45+
import com.networknt.schema.JsonSchemaFactory;
46+
import com.networknt.schema.SpecVersion.VersionFlag;
47+
import com.networknt.schema.ValidationMessage;
4648

4749
/**
4850
* Verifies an SPDX document and lists any verification errors
@@ -171,18 +173,17 @@ public static List<String> verify(String filePath, SerFileType fileType) throws
171173
} else {
172174
jsonSchemaResource = JSON_SCHEMA_RESOURCE_V3;
173175
}
174-
SchemaRegistry schemaRegistry =
175-
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
176-
Schema schema;
176+
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
177+
JsonSchema schema;
177178
try (InputStream is = Verify.class.getResourceAsStream("/" + jsonSchemaResource)) {
178-
schema = schemaRegistry.getSchema(is);
179+
schema = jsonSchemaFactory.getSchema(is);
179180
}
180181
JsonNode root;
181182
try (InputStream is = new FileInputStream(file)) {
182183
root = JSON_MAPPER.readTree(is);
183184
}
184-
List<Error> messages = schema.validate(root);
185-
for (Error msg:messages) {
185+
Set<ValidationMessage> messages = schema.validate(root);
186+
for (ValidationMessage msg:messages) {
186187
retval.add(msg.toString());
187188
}
188189
} catch (IOException e) {

0 commit comments

Comments
 (0)