Skip to content

Commit c56e9dc

Browse files
authored
Fix functional tests that do not validate (#111)
* fix some test cases that do not pass schema validation Signed-off-by: Matt Rutkowski <[email protected]> * fix some test cases that do not pass schema validation Signed-off-by: Matt Rutkowski <[email protected]> --------- Signed-off-by: Matt Rutkowski <[email protected]>
1 parent df2e6c4 commit c56e9dc

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

cmd/validate.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package cmd
2020

21-
// "github.com/iancoleman/orderedmap"
2221
import (
2322
"bytes"
2423
"encoding/json"
@@ -31,7 +30,7 @@ import (
3130
"github.com/CycloneDX/sbom-utility/schema"
3231
"github.com/CycloneDX/sbom-utility/utils"
3332
"github.com/spf13/cobra"
34-
"github.com/xeipuuv/gojsonschema"
33+
"github.com/xeipuuv/gojsonschema" // TODO: switch to: https://github.com/santhosh-tekuri/jsonschema
3534
)
3635

3736
const (
@@ -377,3 +376,23 @@ func validateCustom(document *schema.BOM, policyConfig *schema.LicensePolicyConf
377376

378377
return VALID, nil
379378
}
379+
380+
// func isJSONSchema(filePath string) (isSchema bool, err error) {
381+
// isSchema = false
382+
// file, err := os.Open(filePath)
383+
// if err != nil {
384+
// return
385+
// }
386+
// defer file.Close()
387+
// // decode
388+
// decoder := json.NewDecoder(file)
389+
// var jsonData map[string]interface{}
390+
// err = decoder.Decode(&jsonData)
391+
// if err != nil {
392+
// return
393+
// }
394+
// // if schema tag present then likely a schema file (for now)
395+
// _, hasSchema := jsonData["$schema"]
396+
// isSchema = hasSchema
397+
// return
398+
// }

test/cyclonedx/cdx-1-5-license-choice-variants.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"components": [
66
{
77
"name": "Variant 1: id field only",
8+
"type": "library",
89
"licenses": [
910
{
1011
"license": {
@@ -15,16 +16,18 @@
1516
},
1617
{
1718
"name": "Variant 2: name field only",
19+
"type": "library",
1820
"licenses": [
1921
{
2022
"license": {
21-
"id": "MIT"
23+
"name": "MIT"
2224
}
2325
}
2426
]
2527
},
2628
{
2729
"name": "Variant 3: expression only",
30+
"type": "library",
2831
"licenses": [
2932
{
3033
"expression": "MIT OR Apache-2.0"
@@ -33,6 +36,7 @@
3336
},
3437
{
3538
"name": "Variant 4: id and text (attachment)",
39+
"type": "library",
3640
"licenses": [
3741
{
3842
"license": {
@@ -49,6 +53,7 @@
4953
},
5054
{
5155
"name": "Variant 5: id and properties",
56+
"type": "library",
5257
"licenses": [
5358
{
5459
"license": {

0 commit comments

Comments
 (0)