Skip to content

Commit

Permalink
feat(spec1-5): add initial support for spec v1.5
Browse files Browse the repository at this point in the history
This adds the new schemas, `SpecVersion` variables, and updates existing tests to use v1.5. The default `specVersion` set by `NewBOM` is now `SpecVersion1_5`.

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Jun 24, 2023
1 parent 8c95b53 commit a069906
Show file tree
Hide file tree
Showing 12 changed files with 9,615 additions and 15 deletions.
7 changes: 4 additions & 3 deletions cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ type BOM struct {

func NewBOM() *BOM {
return &BOM{
JSONSchema: jsonSchemas[SpecVersion1_4],
XMLNS: xmlNamespaces[SpecVersion1_4],
JSONSchema: jsonSchemas[SpecVersion1_5],
XMLNS: xmlNamespaces[SpecVersion1_5],
BOMFormat: BOMFormat,
SpecVersion: SpecVersion1_4,
SpecVersion: SpecVersion1_5,
Version: 1,
}
}
Expand Down Expand Up @@ -477,6 +477,7 @@ const (
SpecVersion1_2 // 1.2
SpecVersion1_3 // 1.3
SpecVersion1_4 // 1.4
SpecVersion1_5 // 1.5
)

type SWID struct {
Expand Down
1 change: 1 addition & 0 deletions cyclonedx_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ var jsonSchemas = map[SpecVersion]string{
SpecVersion1_2: "http://cyclonedx.org/schema/bom-1.2.schema.json",
SpecVersion1_3: "http://cyclonedx.org/schema/bom-1.3.schema.json",
SpecVersion1_4: "http://cyclonedx.org/schema/bom-1.4.schema.json",
SpecVersion1_5: "http://cyclonedx.org/schema/bom-1.5.schema.json",
}
5 changes: 3 additions & 2 deletions cyclonedx_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cyclonedx_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ var xmlNamespaces = map[SpecVersion]string{
SpecVersion1_2: "http://cyclonedx.org/schema/bom/1.2",
SpecVersion1_3: "http://cyclonedx.org/schema/bom/1.3",
SpecVersion1_4: "http://cyclonedx.org/schema/bom/1.4",
SpecVersion1_5: "http://cyclonedx.org/schema/bom/1.5",
}
18 changes: 9 additions & 9 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func TestJsonBOMEncoder_SetPretty(t *testing.T) {
require.NoError(t, encoder.Encode(bom))

assert.Equal(t, `{
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"specVersion": "1.5",
"version": 1,
"metadata": {
"authors": [
Expand Down Expand Up @@ -83,9 +83,9 @@ func TestJsonBOMEncoder_SetEscapeHTML_true(t *testing.T) {
require.NoError(t, encoder.Encode(bom))

assert.Equal(t, `{
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"specVersion": "1.5",
"version": 1,
"metadata": {
"authors": [
Expand Down Expand Up @@ -116,9 +116,9 @@ func TestJsonBOMEncoder_SetEscapeHTML_false(t *testing.T) {
require.NoError(t, encoder.Encode(bom))

assert.Equal(t, `{
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"specVersion": "1.5",
"version": 1,
"metadata": {
"authors": [
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestXmlBOMEncoder_SetPretty(t *testing.T) {
require.NoError(t, encoder.Encode(bom))

assert.Equal(t, `<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" version="1">
<bom xmlns="http://cyclonedx.org/schema/bom/1.5" version="1">
<metadata>
<authors>
<author>
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestJsonBOMEncoder_EncodeVersion(t *testing.T) {
require.ErrorContains(t, err, "not supported")
})

for _, version := range []SpecVersion{SpecVersion1_2, SpecVersion1_3, SpecVersion1_4} {
for _, version := range []SpecVersion{SpecVersion1_2, SpecVersion1_3, SpecVersion1_4, SpecVersion1_5} {
t.Run(version.String(), func(t *testing.T) {
// Read original BOM JSON
inputFile, err := os.Open("./testdata/valid-bom.json")
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestJsonBOMEncoder_EncodeVersion(t *testing.T) {
}

func TestXmlBOMEncoder_EncodeVersion(t *testing.T) {
for _, version := range []SpecVersion{SpecVersion1_0, SpecVersion1_1, SpecVersion1_2, SpecVersion1_3, SpecVersion1_4} {
for _, version := range []SpecVersion{SpecVersion1_0, SpecVersion1_1, SpecVersion1_2, SpecVersion1_3, SpecVersion1_4, SpecVersion1_5} {
t.Run(version.String(), func(t *testing.T) {
// Read original BOM JSON
inputFile, err := os.Open("./testdata/valid-bom.xml")
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Example_encode() {

// Output:
// <?xml version="1.0" encoding="UTF-8"?>
// <bom xmlns="http://cyclonedx.org/schema/bom/1.4" version="1">
// <bom xmlns="http://cyclonedx.org/schema/bom/1.5" version="1">
// <metadata>
// <component bom-ref="pkg:golang/acme-inc/[email protected]" type="application">
// <name>ACME Application</name>
Expand Down
Loading

0 comments on commit a069906

Please sign in to comment.