Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/jsonschemautil/jsonschemautil.go
2658 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package jsonschemautil
5
6
import (
7
"os"
8
9
"github.com/goccy/go-yaml"
10
"github.com/santhosh-tekuri/jsonschema/v6"
11
)
12
13
func Validate(schemafile, instancefile string) error {
14
compiler := jsonschema.NewCompiler()
15
schema, err := compiler.Compile(schemafile)
16
if err != nil {
17
return err
18
}
19
instance, err := os.ReadFile(instancefile)
20
if err != nil {
21
return err
22
}
23
var y any
24
err = yaml.Unmarshal(instance, &y)
25
if err != nil {
26
return err
27
}
28
return schema.Validate(y)
29
}
30
31