Skip to content
Open
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 src/main/java/org/spdx/tools/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static List<String> verify(String filePath, SerFileType fileType) throws
try {
String jsonSchemaResource;
if (SerFileType.JSON.equals(fileType)) {
jsonSchemaResource = Version.versionLessThan(Version.TWO_POINT_THREE_VERSION, doc.getSpecVersion()) ?
jsonSchemaResource = Version.versionLessThan(doc.getSpecVersion(), Version.TWO_POINT_THREE_VERSION) ?
JSON_SCHEMA_RESOURCE_V2_2 : JSON_SCHEMA_RESOURCE_V2_3;
} else {
jsonSchemaResource = JSON_SCHEMA_RESOURCE_V3;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/spdx/tools/VerifyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class VerifyTest extends TestCase {
static final String JSON_V2_3_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-v2.3.spdx.json";
static final String JSON_V2_2_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-v2.2.spdx.json";
static final String JSON_BAD_VERSION_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-wrongversion.spdx.json";
static final String JSON_V2_2_WRONG_REF_CATEGORY_FILE_PATH = TEST_DIR + File.separator + "SPDXJSONExample-v2.2-wrongrefcategory.spdx.json";
static final String TEST_V23_FIELDS_IN_V22_FILE = TEST_DIR + File.separator + "SPDXWrongVersion.spdx.json";
static final String TEST_RDF_FILE_PATH = TEST_DIR + File.separator + "SPDXRdfExample-v2.3.spdx.rdf";
static final String TEST_SPREADSHEET_XLS_FILE_PATH = TEST_DIR + File.separator + "SPDXSpreadsheetExample-v2.3.xls";
Expand Down Expand Up @@ -106,6 +107,15 @@ public void testVerifyJSONVersion() throws SpdxVerificationException {
assertFalse(result.isEmpty());
}

// A 2.2 document must be checked against the 2.2 schema, where the 2.3
// reference category spellings are not yet valid - see issue #74
public void testVerifyJSONVersionSchema() throws SpdxVerificationException {
List<String> result = Verify.verify(JSON_V2_2_WRONG_REF_CATEGORY_FILE_PATH, SerFileType.JSON);
assertEquals(1, result.size());
assertTrue(result.get(0).contains("referenceCategory"));
assertTrue(result.get(0).contains("does not have a value in the enumeration"));
}

public void testVerifyDouble() throws SpdxVerificationException {
List<String> result = Verify.verify(DOUBLE_JSON_LD_FILE_PATH, SerFileType.JSONLD);
assertEquals(0, result.size());
Expand Down
26 changes: 26 additions & 0 deletions testResources/SPDXJSONExample-v2.2-wrongrefcategory.spdx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"SPDXID" : "SPDXRef-DOCUMENT",
"spdxVersion" : "SPDX-2.2",
"creationInfo" : {
"created" : "2026-11-10T00:00:00Z",
"creators" : [ "Tool: test" ]
},
"name" : "wrong-reference-category",
"dataLicense" : "CC0-1.0",
"documentNamespace" : "https://example.com/wrong-reference-category",
"documentDescribes" : [ "SPDXRef-Package" ],
"packages" : [ {
"SPDXID" : "SPDXRef-Package",
"name" : "package",
"downloadLocation" : "NOASSERTION",
"filesAnalyzed" : false,
"copyrightText" : "NOASSERTION",
"licenseConcluded" : "NOASSERTION",
"licenseDeclared" : "NOASSERTION",
"externalRefs" : [ {
"referenceCategory" : "PACKAGE-MANAGER",
"referenceType" : "purl",
"referenceLocator" : "pkg:maven/org.apache.commons/commons-lang3@3.22.0"
} ]
} ]
}