Kindsys: Replace DefForGen with kindsys.Kind (#62642)

* Kindsys: Replace DeclForGen with kindsys.Kind

DeclForGen was always unnecessary - it just wasn't obvious on initial
implementation, when we were focused on generating unique types for each
core kind. This removes it, considerably simplifying interactions with
kindsys - virtually everything now just relies on kindsys.Kind and its
derived interfaces.

* Removed unused jenny

* Rename params in jennies
This commit is contained in:
sam boyer
2023-01-31 19:40:15 -05:00
committed by GitHub
parent 0f0a53fbbb
commit 30b4205521
25 changed files with 273 additions and 543 deletions

View File

@ -15,6 +15,7 @@ import (
"cuelang.org/go/cue/cuecontext"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/thema/encoding/jsonschema"
"github.com/olekukonko/tablewriter"
"github.com/xeipuuv/gojsonpointer"
@ -34,8 +35,13 @@ func (j docsJenny) JennyName() string {
return "DocsJenny"
}
func (j docsJenny) Generate(def *DefForGen) (*codejen.File, error) {
f, err := jsonschema.GenerateSchema(def.Lineage().Latest())
func (j docsJenny) Generate(kind kindsys.Kind) (*codejen.File, error) {
// TODO remove this once codejen catches nils https://github.com/grafana/codejen/issues/5
if kind == nil {
return nil, nil
}
f, err := jsonschema.GenerateSchema(kind.Lineage().Latest())
if err != nil {
return nil, fmt.Errorf("failed to generate json representation for the schema: %v", err)
}
@ -61,10 +67,10 @@ func (j docsJenny) Generate(def *DefForGen) (*codejen.File, error) {
// fixes the references between the types within a json after making components.schema.<types> the root of the json
kindJsonStr := strings.Replace(string(obj.Components.Schemas), "#/components/schemas/", "#/", -1)
kindProps := def.Properties.Common()
kindProps := kind.Props().Common()
data := templateData{
KindName: kindProps.Name,
KindVersion: def.Lineage().Latest().Version().String(),
KindVersion: kind.Lineage().Latest().Version().String(),
KindMaturity: string(kindProps.Maturity),
Markdown: "{{ .Markdown 1 }}",
}