Sources/SBOMModel/README.md
This document describes how to manage SBOM specification versions in SwiftPM.
The SBOMVersionRegistry maintains the most recent minor version for each major version of supported SBOM specifications (CycloneDX and SPDX).
SwiftPM supports only the most recent minor version of each major version:
When a new minor version is released (e.g., CycloneDX 1.8 or SPDX 3.1), follow these steps:
In SBOMVersionRegistry.swift, change the version string:
// Before:
internal static let cycloneDX1LatestMinor = "1.7"
// After:
internal static let cycloneDX1LatestMinor = "1.8"
In the Resources directory:
Sources/SBOMModel/CycloneDX/Resources/cyclonedx-1.7.schema.jsonSources/SBOMModel/CycloneDX/Resources/cyclonedx-1.8.schema.jsonUpdate test expectations to use the new version:
// Before:
XCTAssertEqual(spec.version, "1.7")
// After:
XCTAssertEqual(spec.version, "1.8")
The constants should automatically use the new version:
CycloneDXConstants.cyclonedx1SpecVersion → "1.8"CycloneDXConstants.cyclonedx1Schema → "...bom-1.8.schema.json"CycloneDXConstants.cyclonedx1SchemaFile → "cyclonedx-1.8.schema"When a new major version is released (e.g., CycloneDX 2.0 or SPDX 4.0), follow these steps:
Uncomment and set the appropriate version constant:
internal static let cycloneDX2LatestMinor = "2.0" // or spdx4LatestMinor = "4.0"
Add the case to getLatestVersion(for:):
case .cyclonedx2:
return cycloneDX2LatestMinor
Add new case to the Spec enum:
case cyclonedx2 // or spdx4
Update all switch statements to handle the new case.
Add to CycloneDXConstants.swift (or SPDXConstants.swift):
internal static var cyclonedx2SpecVersion: String {
SBOMVersionRegistry.cycloneDX2LatestMinor
}
internal static var cyclonedx2Schema: String {
"http://cyclonedx.org/schema/bom-\(cyclonedx2SpecVersion).schema.json"
}
internal static var cyclonedx2SchemaFile: String {
"cyclonedx-\(cyclonedx2SpecVersion).schema"
}
encodeSBOMData(spec:) switch statementgetSchemaFilename(from:) switch statementIn CycloneDXConverter.swift (or SPDXConverter.swift):
Add the schema file to Resources:
Sources/SBOMModel/CycloneDX/Resources/cyclonedx-2.0.schema.jsonSources/SBOMModel/SPDX/Resources/spdx-4.0.schema.jsonThe registry provides a central method to get the latest supported version for any spec type:
let version = SBOMVersionRegistry.getLatestVersion(for: spec)