jennies

package
v0.15.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const GoTypesMaxDepth = 5

Variables

This section is empty.

Functions

func BackendPluginMainGenerator

func BackendPluginMainGenerator(projectRepo, apiCodegenPath string, generatedKindsAreVersioned bool) codejen.ManyToOne[codegen.Kind]

BackendPluginMainGenerator returns a many-to-one jenny which generates the `main.go` file needed to run the backend plugin.

func CRDGenerator

func CRDGenerator(encoder CRDOutputEncoder, extension string) codejen.OneToOne[codegen.Kind]

func CUEToCRDOpenAPI

func CUEToCRDOpenAPI(v cue.Value, name, version string) (map[string]any, error)

func CUEValueToOAPIYAML

func CUEValueToOAPIYAML(val cue.Value, cfg CUEOpenAPIConfig) ([]byte, error)

func CUEValueToOpenAPI

func CUEValueToOpenAPI(val cue.Value, cfg CUEOpenAPIConfig) (*ast.File, error)

CUEValueToOpenAPI converts a cue.Value into an OpenAPI ast.File

func CUEValueToString

func CUEValueToString(v cue.Value) string

CUEValueToString returns a formatted string output of a cue.Value. This is a more detailed string than using fmt.Println(v), as it will include optional fields and definitions.

func GoTypesFromCUE

func GoTypesFromCUE(v cue.Value, cfg CUEGoConfig, maxNamingDepth int) ([]byte, error)

func KindVersionToCRDSpecVersion

func KindVersionToCRDSpecVersion(kv codegen.KindVersion, kindName string, stored bool) (k8s.CustomResourceDefinitionSpecVersion, error)

func OperatorMainJenny

func OperatorMainJenny(projectRepo, codegenPath string, generatedKindsAreVersioned bool) codejen.ManyToOne[codegen.Kind]

func RouterCodeGenerator

func RouterCodeGenerator(projectRepo string) codejen.ManyToOne[codegen.Kind]

func RouterHandlerCodeGenerator

func RouterHandlerCodeGenerator(projectRepo, apiCodegenPath string, generatedKindsAreVersioned bool) codejen.OneToOne[codegen.Kind]

func SelEq

func SelEq(s1, s2 cue.Selector) bool

SelEq indicates whether two selectors are equivalent. Selectors are equivalent if they are either exactly equal, or if they are equal ignoring path optionality.

func StaticManyToOneGenerator

func StaticManyToOneGenerator[Input any](file codejen.File) codejen.ManyToOne[Input]

func ToPackageName

func ToPackageName(input string) string

ToPackageName sanitizes an input into a deterministic allowed go package name. It is used to turn kind names or versions into package names when performing go code generation.

func TrimPathPrefix

func TrimPathPrefix(path, prefix cue.Path) cue.Path

func WatcherJenny

func WatcherJenny(projectRepo, codegenPath string, generatedKindsAreVersioned bool) codejen.OneToOne[codegen.Kind]

Types

type CRDOutputEncoder

type CRDOutputEncoder func(any) ([]byte, error)

CRDOutputEncoder is a function which marshals an object into a desired output format

type CUEGoConfig

type CUEGoConfig struct {
	PackageName             string
	Name                    string
	Version                 string
	IgnoreDiscoveredImports bool

	// ApplyFuncs is a slice of AST manipulation funcs that will be executed against
	// the generated Go file prior to running it through goimports. For each slice
	// element, [dstutil.Apply] is called with the element as the "pre" parameter.
	ApplyFuncs []dstutil.ApplyFunc

	// UseGoDeclInComments sets the name of the fields and structs at the beginning of each comment.
	UseGoDeclInComments bool
}

type CUEOpenAPIConfig

type CUEOpenAPIConfig struct {
	Name             string
	Version          string
	ExpandReferences bool
	NameFunc         func(cue.Value, cue.Path) string
}

type CodecGenerator added in v0.15.0

type CodecGenerator struct {
	// This flag exists for compatibility with thema codegen, which only generates code for the current/latest version of the kind
	OnlyUseCurrentVersion bool
}

func (*CodecGenerator) Generate added in v0.15.0

func (c *CodecGenerator) Generate(kind codegen.Kind) (codejen.Files, error)

Generate creates one or more codec go files for the provided Kind nolint:dupl

func (*CodecGenerator) JennyName added in v0.15.0

func (*CodecGenerator) JennyName() string

type GoTypes

type GoTypes struct {
	// GenerateOnlyCurrent should be set to true if you only want to generate code for the kind.Properties().Current version.
	// This will affect the package and path(s) of the generated file(s).
	GenerateOnlyCurrent bool

	// Depth represents the tree depth for creating go types from fields. A Depth of 0 will return one go type
	// (plus any definitions used by that type), a Depth of 1 will return a file with a go type for each top-level field
	// (plus any definitions encompassed by each type), etc. Note that types are _not_ generated for fields above the Depth
	// level--i.e. a Depth of 1 will generate go types for each field within the KindVersion.Schema, but not a type for the
	// Schema itself. Because Depth results in recursive calls, the highest value is bound to a max of GoTypesMaxDepth.
	Depth int

	// NamingDepth determines how types are named in relation to Depth. If Depth <= NamingDepth, the go types are named
	// using the field name of the type. Otherwise, Names used are prefixed by field names between Depth and NamingDepth.
	// Typically, a value of 0 is "safest" for NamingDepth, as it prevents overlapping names for types.
	// However, if you know that your fields have unique names up to a certain depth, you may configure this to be higher.
	NamingDepth int
}

GoTypes is a Jenny for turning a codegen.Kind into go types according to its codegen settings.

func (*GoTypes) Generate

func (g *GoTypes) Generate(kind codegen.Kind) (codejen.Files, error)

func (*GoTypes) JennyName

func (*GoTypes) JennyName() string

type OperatorConfigJenny

type OperatorConfigJenny struct {
}

func (*OperatorConfigJenny) Generate

func (o *OperatorConfigJenny) Generate(_ ...codegen.Kind) (*codejen.File, error)

func (*OperatorConfigJenny) JennyName

func (*OperatorConfigJenny) JennyName() string

type OperatorKubeConfigJenny

type OperatorKubeConfigJenny struct {
}

func (*OperatorKubeConfigJenny) Generate

func (o *OperatorKubeConfigJenny) Generate(_ ...codegen.Kind) (*codejen.File, error)

func (*OperatorKubeConfigJenny) JennyName

func (*OperatorKubeConfigJenny) JennyName() string

type ResourceObjectGenerator

type ResourceObjectGenerator struct {
	// This flag exists for compatibility with thema codegen, which only generates code for the current/latest version of the kind
	OnlyUseCurrentVersion bool
}

func (*ResourceObjectGenerator) Generate

func (r *ResourceObjectGenerator) Generate(kind codegen.Kind) (codejen.Files, error)

func (*ResourceObjectGenerator) JennyName

func (*ResourceObjectGenerator) JennyName() string

type SchemaGenerator

type SchemaGenerator struct {
	// This flag exists for compatibility with thema codegen, which only generates code for the current/latest version of the kind
	OnlyUseCurrentVersion bool
}

func (*SchemaGenerator) Generate

func (s *SchemaGenerator) Generate(kind codegen.Kind) (codejen.Files, error)

Generate creates one or more schema go files for the provided Kind nolint:dupl

func (*SchemaGenerator) JennyName

func (*SchemaGenerator) JennyName() string

type TypeScriptResourceTypes added in v0.15.0

type TypeScriptResourceTypes struct {
	GenerateOnlyCurrent bool
}

func (*TypeScriptResourceTypes) Generate added in v0.15.0

func (t *TypeScriptResourceTypes) Generate(kind codegen.Kind) (codejen.Files, error)

func (*TypeScriptResourceTypes) JennyName added in v0.15.0

func (*TypeScriptResourceTypes) JennyName() string

type TypeScriptTypes

type TypeScriptTypes struct {
	// GenerateOnlyCurrent should be set to true if you only want to generate code for the kind.Properties().Current version.
	// This will affect the package and path(s) of the generated file(s).
	GenerateOnlyCurrent bool

	// Depth represents the tree depth for creating go types from fields. A Depth of 0 will return one go type
	// (plus any definitions used by that type), a Depth of 1 will return a file with a go type for each top-level field
	// (plus any definitions encompassed by each type), etc. Note that types are _not_ generated for fields above the Depth
	// level--i.e. a Depth of 1 will generate go types for each field within the KindVersion.Schema, but not a type for the
	// Schema itself. Because Depth results in recursive calls, the highest value is bound to a max of GoTypesMaxDepth.
	Depth int

	// NamingDepth determines how types are named in relation to Depth. If Depth <= NamingDepth, the go types are named
	// using the field name of the type. Otherwise, Names used are prefixed by field names between Depth and NamingDepth.
	// Typically, a value of 0 is "safest" for NamingDepth, as it prevents overlapping names for types.
	// However, if you know that your fields have unique names up to a certain depth, you may configure this to be higher.
	NamingDepth int
}

TypeScriptTypes is a one-to-many jenny that generates one or more TypeScript types for a kind. Each type is a specific version of the kind where codegen.frontend is true. If GenerateOnlyCurrent is true, then all other versions of the kind will be ignored and only the kind.Propertoes().Current version will be used for TypeScript type generation (this will impact the generated file path).

func (TypeScriptTypes) Generate

func (j TypeScriptTypes) Generate(kind codegen.Kind) (codejen.Files, error)

func (TypeScriptTypes) JennyName

func (TypeScriptTypes) JennyName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL