Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spec1-5): add initial support for spec v1.5 #99

Merged
merged 1 commit into from
Jun 24, 2023
Merged
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
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/acme-app@v1.0.0" type="application">
// <name>ACME Application</name>
Expand Down
Loading