Skip to content

feat: prototype 3.0 model #247

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: '1.23'
- name: Run tests
run: make test
- name: Send coverage report to coveralls
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ format:

.PHONY: unit
unit:
go test -v -covermode=count -coverprofile=profile.cov ./...
go test -v -covermode=count -coverprofile=profile.cov.tmp ./...
cat profile.cov.tmp | grep -v /model.go > profile.cov # ignore generated model file

.PHONY: fuzz
fuzz:
Expand Down
13 changes: 8 additions & 5 deletions convert/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import (
converter "github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/common"
"github.com/spdx/tools-golang/spdx/v2/v2_1"
"github.com/spdx/tools-golang/spdx/v2/v2_2"
"github.com/spdx/tools-golang/spdx/v2/v2_3"
"github.com/spdx/tools-golang/spdx/v3/v3_0"
)

var DocumentChain = converter.NewChain(
v2_1.Document{},
v2_2.Document{},
v2_3.Document{},
var DocumentChain = converter.NewFuncChain(
v2_3.To_v2_2, v2_3.From_v2_2,
v2_2.From_v2_1, v2_2.To_v2_1,
v3_0.From_v2_3,
)

//).
// AutoPackageConverter(v3_0.Document{}, v2_3.Document{})

// Document converts from one document to another document
// For example, converting a document to the latest version could be done like:
//
Expand Down
15 changes: 12 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
module github.com/spdx/tools-golang

go 1.13
go 1.23.5

require (
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160
github.com/davecgh/go-spew v1.1.1
github.com/google/go-cmp v0.6.0
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb
github.com/kzantow/go-ld v0.0.0-20250305231540-23fb13522625
github.com/pmezard/go-difflib v1.0.0
github.com/spdx/gordf v0.0.0-20250128162952-000978ccd6fb
github.com/stretchr/testify v1.10.0
sigs.k8s.io/yaml v1.4.0
)

require (
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
23 changes: 10 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1rlcoLz8y5B2r4tTLMiVTrMtpfY0O8EScKJxaSaEc=
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160 h1:r8/1fxpbDMlQO6GgQiud1uL5eAu3p/NVUmfNx95/KY8=
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kzantow/go-ld v0.0.0-20250305231540-23fb13522625 h1:xFbgOwCtZx5bu7Ggnn1eHhPyjIG2vtQgpio5zH6onUU=
github.com/kzantow/go-ld v0.0.0-20250305231540-23fb13522625/go.mod h1:P7HdHSjYOcim2o9GWUj011qCd9bEOc+Bg8SeW6JKV8M=
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b h1:xyh6boGzDR4EpdEDe9ix1KhHNgOSiBjBocahA6FalEQ=
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b/go.mod h1:RVhE35veDX19r5gfUAR+IYHkAUuPwJO8Ie/qVeFaIzw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb h1:bLo8hvc8XFm9J47r690TUKBzcjSWdJDxmjXJZ+/f92U=
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb/go.mod h1:uKWaldnbMnjsSAXRurWqqrdyZen1R7kxl8TkmWk2OyM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/spdx/gordf v0.0.0-20250128162952-000978ccd6fb h1:7G2Czq97VORM5xNRrD8tSQdhoXPRs8s+Otlc7st9TS0=
github.com/spdx/gordf v0.0.0-20250128162952-000978ccd6fb/go.mod h1:uKWaldnbMnjsSAXRurWqqrdyZen1R7kxl8TkmWk2OyM=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
Expand Down
9 changes: 0 additions & 9 deletions spdx/v2/v2_1/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package v2_1

import (
converter "github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/v2/common"
)

Expand Down Expand Up @@ -70,10 +68,3 @@ type Document struct {
// DEPRECATED in version 2.0 of spec
Reviews []*Review `json:"-"`
}

func (d *Document) ConvertFrom(_ interface{}) error {
d.SPDXVersion = Version
return nil
}

var _ converter.ConvertFrom = (*Document)(nil)
10 changes: 5 additions & 5 deletions spdx/v2/v2_2/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"encoding/json"
"fmt"

converter "github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/v2/common"
"github.com/spdx/tools-golang/spdx/v2/v2_1"
)

const Version = "SPDX-2.2"
Expand Down Expand Up @@ -74,12 +73,13 @@ type Document struct {
Reviews []*Review `json:"-"`
}

func (d *Document) ConvertFrom(_ interface{}) error {
func From_v2_1(_ v2_1.Document, d *Document) {
d.SPDXVersion = Version
return nil
}

var _ converter.ConvertFrom = (*Document)(nil)
func To_v2_1(_ Document, d *v2_1.Document) {
d.SPDXVersion = v2_1.Version
}

func (d *Document) UnmarshalJSON(b []byte) error {
type doc Document
Expand Down
10 changes: 5 additions & 5 deletions spdx/v2/v2_3/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"encoding/json"
"fmt"

converter "github.com/anchore/go-struct-converter"

"github.com/spdx/tools-golang/spdx/v2/common"
"github.com/spdx/tools-golang/spdx/v2/v2_2"
)

const Version = "SPDX-2.3"
Expand Down Expand Up @@ -73,12 +72,13 @@ type Document struct {
Reviews []*Review `json:"-" yaml:"-"`
}

func (d *Document) ConvertFrom(_ interface{}) error {
func From_v2_2(_ v2_2.Document, d *Document) {
d.SPDXVersion = Version
return nil
}

var _ converter.ConvertFrom = (*Document)(nil)
func To_v2_2(_ Document, d *v2_2.Document) {
d.SPDXVersion = v2_2.Version
}

func (d *Document) UnmarshalJSON(b []byte) error {
type doc Document
Expand Down
Loading
Loading