coremodels: Convert plugin-metadata schema to a coremodel (#52121)
* coremodels: Convert plugin-metadata schema to a coremodel * Newer cuetsy; try quoting field name * Add APIType control concept, regen pluginmeta * Use proper numeric types for schema fields
This commit is contained in:
@@ -72,12 +72,15 @@ func main() {
|
||||
}
|
||||
wd.Merge(gofiles)
|
||||
|
||||
tsfiles, err := ls.GenerateTypescriptCoremodel(filepath.Join(tsroot, ls.Lineage.Name()))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to generate TypeScript for %s: %s\n", ls.Lineage.Name(), err)
|
||||
os.Exit(1)
|
||||
// Only generate TS for API types
|
||||
if ls.IsAPIType {
|
||||
tsfiles, err := ls.GenerateTypescriptCoremodel(filepath.Join(tsroot, ls.Lineage.Name()))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to generate TypeScript for %s: %s\n", ls.Lineage.Name(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
wd.Merge(tsfiles)
|
||||
}
|
||||
wd.Merge(tsfiles)
|
||||
}
|
||||
|
||||
regfiles, err := gcgen.GenerateCoremodelRegistry(filepath.Join(groot, "pkg", "framework", "coremodel", "registry", "registry_gen.go"), lins)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/coremodel/dashboard"
|
||||
"github.com/grafana/grafana/pkg/coremodel/pluginmeta"
|
||||
"github.com/grafana/grafana/pkg/framework/coremodel"
|
||||
"github.com/grafana/thema"
|
||||
)
|
||||
@@ -23,13 +24,15 @@ import (
|
||||
// Prefer All() when performing operations generically across all coremodels. For example,
|
||||
// a validation HTTP middleware for any coremodel-schematized object type.
|
||||
type Base struct {
|
||||
all []coremodel.Interface
|
||||
dashboard *dashboard.Coremodel
|
||||
all []coremodel.Interface
|
||||
dashboard *dashboard.Coremodel
|
||||
pluginmeta *pluginmeta.Coremodel
|
||||
}
|
||||
|
||||
// type guards
|
||||
var (
|
||||
_ coremodel.Interface = &dashboard.Coremodel{}
|
||||
_ coremodel.Interface = &pluginmeta.Coremodel{}
|
||||
)
|
||||
|
||||
// Dashboard returns the dashboard coremodel. The return value is guaranteed to
|
||||
@@ -38,6 +41,12 @@ func (s *Base) Dashboard() *dashboard.Coremodel {
|
||||
return s.dashboard
|
||||
}
|
||||
|
||||
// Pluginmeta returns the pluginmeta coremodel. The return value is guaranteed to
|
||||
// implement coremodel.Interface.
|
||||
func (s *Base) Pluginmeta() *pluginmeta.Coremodel {
|
||||
return s.pluginmeta
|
||||
}
|
||||
|
||||
func doProvideBase(lib thema.Library) *Base {
|
||||
var err error
|
||||
reg := &Base{}
|
||||
@@ -48,5 +57,11 @@ func doProvideBase(lib thema.Library) *Base {
|
||||
}
|
||||
reg.all = append(reg.all, reg.dashboard)
|
||||
|
||||
reg.pluginmeta, err = pluginmeta.New(lib)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error while initializing pluginmeta coremodel: %s", err))
|
||||
}
|
||||
reg.all = append(reg.all, reg.pluginmeta)
|
||||
|
||||
return reg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user