Documentation
¶
Index ¶
- func GenGrafanaHeader(vars HeaderVars) string
- func PrefixDropper(prefix string) dstutil.ApplyFunc
- func PrefixReplacer(prefix, replace string) dstutil.ApplyFunc
- func SlashHeaderMapper(maingen string) codejen.FileMapper
- type Any
- type CoreKindJennyConfig
- type CoremodelDeclaration
- type GoTypesJenny
- type HeaderVars
- type ManyToMany
- type ManyToOne
- type OneToMany
- type OneToOne
- type PropertyType
- type PropertyTypes
- type SchemaForGen
- type TSTypesJenny
- type WriteDiffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenGrafanaHeader ¶
func GenGrafanaHeader(vars HeaderVars) string
GenGrafanaHeader creates standard header elements for generated Grafana files.
func PrefixDropper ¶
PrefixDropper returns a dstutil.ApplyFunc that removes the provided prefix string when it appears as a leading sequence in type names, var names, and comments in a generated Go file.
func PrefixReplacer ¶
PrefixReplacer returns a dstutil.ApplyFunc that removes the provided prefix string when it appears as a leading sequence in type names, var names, and comments in a generated Go file.
When an exact match for prefix is found, the provided replace string is substituted.
func SlashHeaderMapper ¶
func SlashHeaderMapper(maingen string) codejen.FileMapper
SlashHeaderMapper produces a FileMapper that injects a comment header onto a codejen.File indicating the main generator that produced it (via the provided maingen, which should be a path) and the jenny or jennies that constructed the file.
Types ¶
type Any ¶
type Any struct {
// contains filtered or unexported fields
}
func (*Any) UnmarshalJSON ¶
type CoreKindJennyConfig ¶
type CoreKindJennyConfig struct {
// GenDirName returns the name of the directory in which the file should be
// generated. Defaults to DefForGen.Lineage().Name() if nil.
GenDirName func(kindsys.Kind) string
}
CoreKindJennyConfig holds configuration options for CoreKindJenny.
type CoremodelDeclaration ¶
type CoremodelDeclaration struct {
Lineage thema.Lineage
// Absolute path to the coremodel's coremodel.cue file.
LineagePath string
// Path to the coremodel's coremodel.cue file relative to repo root.
RelativePath string
// Indicates whether the coremodel is considered canonical or not. Generated
// code from not-yet-canonical coremodels should include appropriate caveats in
// documentation and possibly be hidden from external public API surface areas.
IsCanonical bool
// Indicates whether the coremodel represents an API type, and should therefore
// be included in API client code generation.
IsAPIType bool
}
CoremodelDeclaration contains the results of statically analyzing a Grafana directory for a Thema lineage.
func ExtractLineage ¶
func ExtractLineage(path string, rt *thema.Runtime) (*CoremodelDeclaration, error)
ExtractLineage loads a Grafana Thema lineage from the filesystem.
The provided path must be the absolute path to the file containing the lineage to be loaded.
This loading approach is intended primarily for use with code generators, or other use cases external to grafana-server backend. For code within grafana-server, prefer lineage loaders provided in e.g. pkg/coremodel/*.
func (*CoremodelDeclaration) GenerateGoCoremodel ¶
func (cd *CoremodelDeclaration) GenerateGoCoremodel(path string) (WriteDiffer, error)
GenerateGoCoremodel generates a standard Go model struct and coremodel implementation from a coremodel CUE declaration.
The provided path must be a directory. Generated code files will be written to that path. The final element of the path must match the Lineage.Name().
func (*CoremodelDeclaration) GenerateTypescriptCoremodel ¶
func (cd *CoremodelDeclaration) GenerateTypescriptCoremodel() (*tsast.File, error)
func (*CoremodelDeclaration) PathVersion ¶
func (cd *CoremodelDeclaration) PathVersion() string
PathVersion returns the string path element to use for the latest schema. "x" if not yet canonical, otherwise, "v<major>"
type GoTypesJenny ¶
GoTypesJenny is a OneToOne that produces Go types for the provided thema.Schema.
func (GoTypesJenny) Generate ¶
func (j GoTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error)
func (GoTypesJenny) JennyName ¶
func (j GoTypesJenny) JennyName() string
type HeaderVars ¶
type HeaderVars = tvars_autogen_header
type ManyToMany ¶
type ManyToMany codejen.ManyToMany[kindsys.Kind]
type ManyToOne ¶
func BaseCoreRegistryJenny ¶
BaseCoreRegistryJenny generates a static registry for core kinds that only initializes their kindsys.Kind. No slot kinds are composed.
Path should be the relative path to the directory that will contain the generated registry. kindrelroot should be the repo-root-relative path to the parent directory to all directories that contain generated kind bindings (e.g. pkg/kind).
func CRDKindRegistryJenny ¶
CRDKindRegistryJenny generates a static registry of the CRD representations of core Grafana kinds, layered on top of the publicly consumable generated registry in pkg/corekinds.
Path should be the relative path to the directory that will contain the generated registry.
func TSVeneerIndexJenny ¶
TSVeneerIndexJenny generates an index.gen.ts file with references to all generated TS types. Elements with the attribute @grafana(TSVeneer="type") are exported from a handwritten file, rather than the raw generated types.
The provided dir is the path, relative to the grafana root, to the directory that should contain the generated index.
Implicitly depends on output patterns in TSTypesJenny. TODO this is wasteful; share-nothing generator model entails re-running the cuetsy gen that TSTypesJenny already did
type OneToMany ¶
func LatestMajorsOrXJenny ¶
func LatestMajorsOrXJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToMany
LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version,
type OneToOne ¶
func CRDTypesJenny ¶
CRDTypesJenny generates the OpenAPI CRD representation for a core structured kind that is expected by Kubernetes controller machinery.
func CoreKindJenny ¶
func CoreKindJenny(gokindsdir string, cfg *CoreKindJennyConfig) OneToOne
CoreKindJenny generates the implementation of kindsys.Core for the provided kind declaration.
gokindsdir should be the relative path to the parent directory that contains all generated kinds.
This generator only has output for core structured kinds.
func LatestJenny ¶
func LatestJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToOne
LatestJenny returns a jenny that runs another jenny for only the latest schema in a DefForGen, and prefixes the resulting file with the provided parentdir (e.g. "pkg/kinds/") and with a directory based on the kind's machine name (e.g. "dashboard/").
func YamlCRDJenny ¶
YamlCRDJenny generates a representation of a core structured kind in YAML CRD form.
type PropertyType ¶
type PropertyType string
const ( PropertyTypeString PropertyType = "string" PropertyTypeNumber PropertyType = "number" PropertyTypeBoolean PropertyType = "boolean" PropertyTypeObject PropertyType = "object" PropertyTypeArray PropertyType = "array" PropertyTypeNull PropertyType = "null" )
type PropertyTypes ¶
type PropertyTypes []PropertyType
func (*PropertyTypes) HasType ¶
func (pts *PropertyTypes) HasType(pt PropertyType) bool
func (*PropertyTypes) UnmarshalJSON ¶
func (pts *PropertyTypes) UnmarshalJSON(data []byte) error
type SchemaForGen ¶
type SchemaForGen struct {
// The PascalCase name of the schematized type.
Name string
// The schema to be rendered for the type itself.
Schema thema.Schema
// Whether the schema is grouped. See https://github.com/grafana/thema/issues/62
IsGroup bool
}
SchemaForGen is an intermediate values type for jennies that holds both a thema.Schema, and values relevant to generating the schema that should properly, eventually, be in thema itself.
TODO this will be replaced by thema-native constructs
func ForLatestSchema ¶
func ForLatestSchema(k kindsys.Kind) SchemaForGen
ForLatestSchema returns a SchemaForGen for the latest schema in the provided kindsys.Kind's lineage.
TODO this will be replaced by thema-native constructs
type TSTypesJenny ¶
type TSTypesJenny struct{}
TSTypesJenny is a OneToOne that produces TypeScript types and defaults for a Thema schema.
Thema's generic TS jenny will be able to replace this one once https://github.com/grafana/thema/issues/89 is complete.
func (TSTypesJenny) Generate ¶
func (j TSTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error)
func (TSTypesJenny) JennyName ¶
func (j TSTypesJenny) JennyName() string
type WriteDiffer ¶
WriteDiffer is a pseudo-filesystem that supports batch-writing its contents to the real filesystem, or batch-comparing its contents to the real filesystem. Its intended use is for idiomatic `go generate`-style code generators, where it is expected that the results of codegen are committed to version control.
In such cases, the normal behavior of a generator is to write files to disk, but in CI, that behavior should change to verify that what is already on disk is identical to the results of code generation. This allows CI to ensure that the results of code generation are always up to date. WriteDiffer supports these related behaviors through its Write() and Verify() methods, respectively.
Note that the statelessness of WriteDiffer means that, if a particular input to the code generator goes away, it will not notice generated files left behind if their inputs are removed. TODO introduce a search/match system
func NewWriteDiffer ¶
func NewWriteDiffer() WriteDiffer
func (WriteDiffer) Merge ¶
func (wd WriteDiffer) Merge(wd2 WriteDiffer) error
Merge combines all the entries from the provided WriteDiffer into the callee WriteDiffer. Duplicate paths result in an error.
func (WriteDiffer) Verify ¶
func (wd WriteDiffer) Verify() error
Verify checks the contents of each file against the filesystem. It emits an error if any of its contained files differ.
func (WriteDiffer) Write ¶
func (wd WriteDiffer) Write() error
Write writes all of the files to their indicated paths.