-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.go
More file actions
32 lines (26 loc) · 716 Bytes
/
Copy pathparse.go
File metadata and controls
32 lines (26 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package ys
import (
"gopkg.in/yaml.v3"
)
// yamlNode wraps yaml.Node for internal use.
type yamlNode = yaml.Node
// Validate parses YAML data and validates it against the given schema.
func Validate(data []byte, schema Schema) (Result, error) {
var doc yaml.Node
if err := yaml.Unmarshal(data, &doc); err != nil {
return Result{}, err
}
// yaml.Unmarshal wraps content in a document node
if doc.Kind != yaml.DocumentNode || len(doc.Content) == 0 {
return Result{
OK: false,
Errors: []SchemaError{{Path: "", Line: 0, Message: "empty document"}},
}, nil
}
root := doc.Content[0]
errors := schema.validate(root, "")
return Result{
OK: len(errors) == 0,
Errors: errors,
}, nil
}