mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
fix: update field plurality of 8.0.0 schema before release (#1820)
to keep things consistent across the schema we want Locations and URLs to be plural fields now that they are fields on the License struct --------- Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
@@ -99,7 +99,7 @@ func separateLicenses(p pkg.Package) (spdx, other cyclonedx.Licenses, expression
|
||||
// singular expression case
|
||||
// only ID field here since we guarantee that the license is valid
|
||||
if value, exists := spdxlicense.ID(l.SPDXExpression); exists {
|
||||
if !l.URL.Empty() {
|
||||
if !l.URLs.Empty() {
|
||||
processLicenseURLs(l, value, &spdxc)
|
||||
continue
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func separateLicenses(p pkg.Package) (spdx, other cyclonedx.Licenses, expression
|
||||
|
||||
// license string that are not valid spdx expressions or ids
|
||||
// we only use license Name here since we cannot guarantee that the license is a valid SPDX expression
|
||||
if !l.URL.Empty() {
|
||||
if !l.URLs.Empty() {
|
||||
processLicenseURLs(l, "", &otherc)
|
||||
continue
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func separateLicenses(p pkg.Package) (spdx, other cyclonedx.Licenses, expression
|
||||
}
|
||||
|
||||
func processLicenseURLs(l pkg.License, spdxID string, populate *cyclonedx.Licenses) {
|
||||
for _, url := range l.URL.ToSlice() {
|
||||
for _, url := range l.URLs.ToSlice() {
|
||||
if spdxID == "" {
|
||||
*populate = append(*populate, cyclonedx.LicenseChoice{
|
||||
License: &cyclonedx.License{
|
||||
|
||||
@@ -137,7 +137,7 @@ func Test_encodeLicense(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with multiple URLs and single with no URL",
|
||||
name: "with multiple URLs and single with no URLs",
|
||||
input: pkg.Package{
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.NewLicense("MIT"),
|
||||
@@ -224,7 +224,7 @@ func TestDecodeLicenses(t *testing.T) {
|
||||
Value: "RandomLicense",
|
||||
// CycloneDX specification doesn't give a field for determining the license type
|
||||
Type: license.Declared,
|
||||
URL: internal.NewStringSet(),
|
||||
URLs: internal.NewStringSet(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -244,7 +244,7 @@ func TestDecodeLicenses(t *testing.T) {
|
||||
Value: "MIT",
|
||||
SPDXExpression: "MIT",
|
||||
Type: license.Declared,
|
||||
URL: internal.NewStringSet(),
|
||||
URLs: internal.NewStringSet(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -263,7 +263,7 @@ func TestDecodeLicenses(t *testing.T) {
|
||||
Value: "MIT AND GPL-3.0-only WITH Classpath-exception-2.0",
|
||||
SPDXExpression: "MIT AND GPL-3.0-only WITH Classpath-exception-2.0",
|
||||
Type: license.Declared,
|
||||
URL: internal.NewStringSet(),
|
||||
URLs: internal.NewStringSet(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -40,8 +40,8 @@ type License struct {
|
||||
Value string `json:"value"`
|
||||
SPDXExpression string `json:"spdxExpression"`
|
||||
Type license.Type `json:"type"`
|
||||
URL []string `json:"url"`
|
||||
Location []source.Location `json:"locations"`
|
||||
URLs []string `json:"urls"`
|
||||
Locations []source.Location `json:"locations"`
|
||||
}
|
||||
|
||||
func newModelLicensesFromValues(licenses []string) (ml []License) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"value": "MIT",
|
||||
"spdxExpression": "MIT",
|
||||
"type": "declared",
|
||||
"url": [],
|
||||
"urls": [],
|
||||
"locations": []
|
||||
}
|
||||
],
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"value": "MIT",
|
||||
"spdxExpression": "MIT",
|
||||
"type": "declared",
|
||||
"url": [],
|
||||
"urls": [],
|
||||
"locations": []
|
||||
}
|
||||
],
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"value": "MIT",
|
||||
"spdxExpression": "MIT",
|
||||
"type": "declared",
|
||||
"url": [],
|
||||
"urls": [],
|
||||
"locations": []
|
||||
}
|
||||
],
|
||||
|
||||
@@ -188,15 +188,15 @@ func toLicenseModel(pkgLicenses []pkg.License) (modelLicenses []model.License) {
|
||||
for _, l := range pkgLicenses {
|
||||
// guarantee collection
|
||||
locations := make([]source.Location, 0)
|
||||
if v := l.Location.ToSlice(); v != nil {
|
||||
if v := l.Locations.ToSlice(); v != nil {
|
||||
locations = v
|
||||
}
|
||||
modelLicenses = append(modelLicenses, model.License{
|
||||
Value: l.Value,
|
||||
SPDXExpression: l.SPDXExpression,
|
||||
Type: l.Type,
|
||||
URL: l.URL.ToSlice(),
|
||||
Location: locations,
|
||||
URLs: l.URLs.ToSlice(),
|
||||
Locations: locations,
|
||||
})
|
||||
}
|
||||
return
|
||||
|
||||
@@ -108,8 +108,8 @@ func toSyftLicenses(m []model.License) (p []pkg.License) {
|
||||
Value: l.Value,
|
||||
SPDXExpression: l.SPDXExpression,
|
||||
Type: l.Type,
|
||||
URL: internal.NewStringSet(l.URL...),
|
||||
Location: source.NewLocationSet(l.Location...),
|
||||
URLs: internal.NewStringSet(l.URLs...),
|
||||
Locations: source.NewLocationSet(l.Locations...),
|
||||
})
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user