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