class
CycloneDX::BOM
- CycloneDX::BOM
- Reference
- Object
Overview
Represents a CycloneDX Bill of Materials (BOM). This class manages a collection of components and provides methods for serializing the BOM into different formats (JSON, XML, CSV).
Included Modules
- JSON::Serializable
Defined in:
cyclonedx/bom.crConstant Summary
-
BOM_FORMAT =
"CycloneDX" -
BOM_VERSION =
1 -
CSV_FORMULA_PREFIXES =
{'=', '+', '-', '@'} -
Characters that make a spreadsheet treat a cell as a formula rather than as text. Excel, LibreOffice and Google Sheets all evaluate such cells on open.
-
JSON_SCHEMA =
"http://cyclonedx.org/schema/bom" -
SUPPORTED_VERSIONS =
["1.4", "1.5", "1.6", "1.7"] -
XML_NAMESPACE =
"http://cyclonedx.org/schema/bom"
Constructors
-
.new(components : Array(Component), spec_version : String, metadata : Metadata | Nil = nil, dependencies : Array(Dependency) | Nil = nil, properties : Array(Property) | Nil = nil, vulnerabilities : Array(Vulnerability) | Nil = nil, services : Array(Service) | Nil = nil, compositions : Array(Composition) | Nil = nil, annotations : Array(Annotation) | Nil = nil, formulation : Array(Formula) | Nil = nil, declarations : Declarations | Nil = nil, external_references : Array(ExternalReference) | Nil = nil, definitions : Definitions | Nil = nil, serial_number : String | Nil = nil)
Initializes a new CycloneDX BOM.
- .new(pull : JSON::PullParser)
Instance Method Summary
- #annotations : Array(Annotation) | Nil
-
#bom_format : String
Specifies the format of the BOM (always "CycloneDX" for JSON serialization).
-
#bom_version : Int32
The version of the BOM itself (not the spec version), typically 1.
-
#components : Array(Component)
An array of
CycloneDX::Componentobjects included in the BOM. -
#compositions : Array(Composition) | Nil
An array of
CycloneDX::Compositionobjects for completeness assertions. - #declarations : Declarations | Nil
-
#definitions : Definitions | Nil
Definitions for standards (1.5+).
-
#dependencies : Array(Dependency) | Nil
An array of
CycloneDX::Dependencyobjects describing component relationships. -
#external_references : Array(ExternalReference) | Nil
An array of
CycloneDX::ExternalReferenceobjects for the BOM itself. - #formulation : Array(Formula) | Nil
-
#metadata : Metadata | Nil
Metadata about the BOM.
-
#properties : Array(Property) | Nil
An array of
CycloneDX::Propertyobjects for extensibility. -
#raw_json : String
The document as
JSON::Serializableproduces it, before spec-version gating. -
#schema_url : String
The
$schemavalue for the declared spec version. -
#serial_number : String
The unique serial number of the BOM.
-
#services : Array(Service) | Nil
An array of
CycloneDX::Serviceobjects for SaaSBOM. -
#spec_version : String
The CycloneDX specification version.
-
#to_csv : String
Serializes the BOM to CSV format.
-
#to_json(json : JSON::Builder) : Nil
Serializes the BOM to JSON.
-
#to_xml : String
Serializes the BOM to XML format.
-
#vulnerabilities : Array(Vulnerability) | Nil
An array of
CycloneDX::Vulnerabilityobjects for VDR/VEX.
Constructor Detail
Initializes a new CycloneDX BOM.
Instance Method Detail
Specifies the format of the BOM (always "CycloneDX" for JSON serialization).
An array of CycloneDX::Component objects included in the BOM.
#components is optional in every CycloneDX version, so it defaults to empty
rather than being required on parse — a BOM that inventories only services,
or that carries nothing but vulnerabilities, legitimately omits it.
An array of CycloneDX::Composition objects for completeness assertions.
An array of CycloneDX::Dependency objects describing component relationships.
An array of CycloneDX::ExternalReference objects for the BOM itself.
An array of CycloneDX::Property objects for extensibility.
The document as JSON::Serializable produces it, before spec-version
gating.
Validator diffs this against the gated document to find fields that are
newer than the declared specVersion, so the rules for what gets stripped
live only in VersionGate and cannot drift out of sync with the validator.
The two documents therefore differ in exactly the places the gate edited.
The $schema value for the declared spec version. The 1.4 and 1.5 JSON
schemas constrain this key to one exact URL, so it is always derived rather
than caller-supplied. XML carries the same information in xmlns.
The unique serial number of the BOM. Randomly generated unless the caller
supplies one; a caller-supplied value is what makes byte-reproducible output
possible (see the CLI's --reproducible).
An array of CycloneDX::Service objects for SaaSBOM.
Serializes the BOM to CSV format.
The root component lives in metadata.component (not in #components), so it
is emitted as the first row to keep the CSV consistent with the JSON/XML
output, which both represent the root component.
Scope and BOM-Ref are appended after the original four columns so a
consumer reading by column index is unaffected.
Serializes the BOM to JSON.
The object model may carry fields newer than the declared specVersion
(e.g. a 1.4 BOM that was handed lifecycles). To keep the output
schema-valid, the raw serialization is filtered through VersionGate,
which strips or downgrades anything newer than @spec_version.
This overrides the JSON::Serializable implementation rather than wrapping
only the no-arg #to_json, because every other JSON entry point in stdlib
(to_pretty_json, #to_json(IO), and serialization as part of a larger
document) funnels through this method. Gating only the no-arg form left all
of those emitting ungated output.
An array of CycloneDX::Vulnerability objects for VDR/VEX.