Schemas: Restore spec core go generation (#83594)

* Restore spec core go generation

* Fix go imports
This commit is contained in:
Selene 2024-02-29 10:20:28 +01:00 committed by GitHub
parent 10721bfcd9
commit f8ce8d0600
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 0 deletions

View File

@ -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(

View 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
}