|
|
|
@ -2,22 +2,18 @@ package obp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
|
|
|
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Validate(schemaURL, filename string) error {
|
|
|
|
|
func Validate(schemaURL string, r io.Reader) error {
|
|
|
|
|
var m interface{}
|
|
|
|
|
|
|
|
|
|
target, err := os.Open(filename)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("could not open target file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
dec := yaml.NewDecoder(target)
|
|
|
|
|
err = dec.Decode(&m)
|
|
|
|
|
dec := yaml.NewDecoder(r)
|
|
|
|
|
err := dec.Decode(&m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error decoding YAML: %w", err)
|
|
|
|
|
}
|
|
|
|
@ -28,7 +24,7 @@ func Validate(schemaURL, filename string) error {
|
|
|
|
|
return fmt.Errorf("error compiling schema: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if err := schema.Validate(m); err != nil {
|
|
|
|
|
return fmt.Errorf("error validating target %q: %w", filename, err)
|
|
|
|
|
return fmt.Errorf("error validating target: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|