mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Schemas: Restore spec core go generation (#83594)
* Restore spec core go generation * Fix go imports
This commit is contained in:
parent
10721bfcd9
commit
f8ce8d0600
@ -39,6 +39,7 @@ func main() {
|
||||
|
||||
// All the jennies that comprise the core kinds generator pipeline
|
||||
coreKindsGen.Append(
|
||||
&codegen.GoSpecJenny{},
|
||||
codegen.CoreKindJenny(cuectx.GoCoreKindParentPath, nil),
|
||||
codegen.BaseCoreRegistryJenny(filepath.Join("pkg", "registry", "corekind"), cuectx.GoCoreKindParentPath),
|
||||
codegen.LatestMajorsOrXJenny(
|
||||
|
46
pkg/codegen/jenny_go_spec.go
Normal file
46
pkg/codegen/jenny_go_spec.go
Normal file
@ -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
Block a user