mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
34 lines
658 B
Go
34 lines
658 B
Go
package csaf
|
|
|
|
import (
|
|
_ "embed"
|
|
|
|
"github.com/xeipuuv/gojsonschema"
|
|
)
|
|
|
|
//go:embed schema/csaf_json_schema.json
|
|
var schema string
|
|
|
|
// Validate validates the document data against the JSON schema
|
|
// of CSAF.
|
|
func Validate(data []byte) ([]string, error) {
|
|
schemaLoader := gojsonschema.NewStringLoader(schema)
|
|
documentLoader := gojsonschema.NewStringLoader(string(data))
|
|
|
|
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if result.Valid() {
|
|
return nil, nil
|
|
}
|
|
|
|
errors := result.Errors()
|
|
res := make([]string, len(errors))
|
|
for i, e := range errors {
|
|
res[i] = e.String()
|
|
}
|
|
|
|
return res, nil
|
|
}
|