forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjenny_go_spec.go
45 lines (37 loc) · 1004 Bytes
/
jenny_go_spec.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
package codegen
import (
"fmt"
"strings"
"cuelang.org/go/cue"
"github.com/dave/dst/dstutil"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/codegen/generators"
)
type GoSpecJenny struct {
ApplyFuncs []dstutil.ApplyFunc
}
func (jenny *GoSpecJenny) JennyName() string {
return "GoResourceTypes"
}
func (jenny *GoSpecJenny) Generate(sfg ...SchemaForGen) (codejen.Files, error) {
files := make(codejen.Files, len(sfg))
for i, v := range sfg {
packageName := strings.ToLower(v.Name)
b, err := generators.GenerateTypesGo(v.CueFile,
&generators.GoConfig{
Config: &generators.OpenApiConfig{
IsGroup: false,
RootName: "Spec",
SubPath: cue.MakePath(cue.Str("spec")),
},
PackageName: packageName,
ApplyFuncs: append(jenny.ApplyFuncs, PrefixDropper(v.Name)),
},
)
if err != nil {
return nil, err
}
files[i] = *codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_spec_gen.go", packageName, packageName), b, jenny)
}
return files, nil
}