mirror of https://github.com/grafana/grafana
Schemas: Restore spec core go generation (#83594)
* Restore spec core go generation * Fix go importspull/83669/head
parent
10721bfcd9
commit
f8ce8d0600
@ -0,0 +1,46 @@ |
||||
package codegen |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"cuelang.org/go/cue" |
||||
"github.com/dave/dst/dstutil" |
||||
"github.com/grafana/codejen" |
||||
"github.com/grafana/kindsys" |
||||
"github.com/grafana/thema/encoding/gocode" |
||||
"github.com/grafana/thema/encoding/openapi" |
||||
) |
||||
|
||||
type GoSpecJenny struct { |
||||
ApplyFuncs []dstutil.ApplyFunc |
||||
} |
||||
|
||||
func (jenny *GoSpecJenny) JennyName() string { |
||||
return "GoResourceTypes" |
||||
} |
||||
|
||||
func (jenny *GoSpecJenny) Generate(kinds ...kindsys.Kind) (codejen.Files, error) { |
||||
files := make(codejen.Files, len(kinds)) |
||||
for i, v := range kinds { |
||||
name := v.Lineage().Name() |
||||
b, err := gocode.GenerateTypesOpenAPI(v.Lineage().Latest(), |
||||
&gocode.TypeConfigOpenAPI{ |
||||
Config: &openapi.Config{ |
||||
Group: false, |
||||
RootName: "Spec", |
||||
Subpath: cue.MakePath(cue.Str("spec")), |
||||
}, |
||||
PackageName: name, |
||||
ApplyFuncs: append(jenny.ApplyFuncs, PrefixDropper(v.Props().Common().Name)), |
||||
}, |
||||
) |
||||
|
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
files[i] = *codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_spec_gen.go", name, name), b, jenny) |
||||
} |
||||
|
||||
return files, nil |
||||
} |
||||
Loading…
Reference in new issue