...
1 package configx
2
3 import (
4 "bytes"
5 "fmt"
6
7 "github.com/google/uuid"
8 "github.com/pkg/errors"
9 "github.com/tidwall/gjson"
10
11 "github.com/ory/jsonschema/v3"
12 )
13
14 func newCompiler(schema []byte) (string, *jsonschema.Compiler, error) {
15 id := gjson.GetBytes(schema, "$id").String()
16 if id == "" {
17 id = fmt.Sprintf("%s.json", uuid.New().String())
18 }
19
20 compiler := jsonschema.NewCompiler()
21 if err := compiler.AddResource(id, bytes.NewBuffer(schema)); err != nil {
22 return "", nil, errors.WithStack(err)
23 }
24 compiler.ExtractAnnotations = true
25
26 return id, compiler, nil
27 }
28
View as plain text