|
|
@ -2,7 +2,6 @@ package obp
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
|
@ -15,23 +14,22 @@ func Validate(schemaURL, filename string) error {
|
|
|
|
|
|
|
|
|
|
|
|
target, err := os.Open(filename)
|
|
|
|
target, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("could not open target file: %s\n", err)
|
|
|
|
return fmt.Errorf("could not open target file: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dec := yaml.NewDecoder(target)
|
|
|
|
dec := yaml.NewDecoder(target)
|
|
|
|
err = dec.Decode(&m)
|
|
|
|
err = dec.Decode(&m)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error decoding YAML: %s\n", err)
|
|
|
|
return fmt.Errorf("error decoding YAML: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
compiler := jsonschema.NewCompiler()
|
|
|
|
compiler := jsonschema.NewCompiler()
|
|
|
|
schema, err := compiler.Compile(schemaURL)
|
|
|
|
schema, err := compiler.Compile(schemaURL)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error compiling schema: %s\n", err)
|
|
|
|
return fmt.Errorf("error compiling schema: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := schema.Validate(m); err != nil {
|
|
|
|
if err := schema.Validate(m); err != nil {
|
|
|
|
log.Fatalf("error validating: %#v\n", err)
|
|
|
|
return fmt.Errorf("error validating target %q: %w", filename, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("validation successfull")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|