codegen

package
v0.0.0-...-e91a082 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StdoutReporter

func StdoutReporter(msg string)

Types

type CueInput

type CueInput struct {
	InputBase `yaml:",inline"`

	// Entrypoint refers to a directory containing CUE files.
	Entrypoint string `yaml:"entrypoint"`

	// Value represents the CUE value to use as an input. If specified, it
	// supersedes the Entrypoint option.
	Value *cue.Value `yaml:"-"`

	// ForcedEnvelope decorates the parsed cue Value with an envelope whose
	// name is given. This is useful for dataqueries for example, where the
	// schema doesn't define any suitable top-level object.
	ForcedEnvelope string `yaml:"forced_envelope"`

	// Package name to use for the input schema. If empty, it will be guessed
	// from the entrypoint.
	Package string `yaml:"package"`

	// CueImports allows importing additional libraries.
	// Format: [path]:[import]. Example: '../grafana/common-library:github.com/grafana/grafana/packages/grafana-schema/src/common
	CueImports []string `yaml:"cue_imports"`

	NameFunc simplecue.NameFunc `yaml:"-"`
}

type Input

type Input struct {
	If string `yaml:"if"`

	JSONSchema *JSONSchemaInput `yaml:"jsonschema"`
	OpenAPI    *OpenAPIInput    `yaml:"openapi"`

	KindRegistry      *KindRegistryInput `yaml:"kind_registry"`
	KindsysCore       *CueInput          `yaml:"kindsys_core"`
	KindsysComposable *CueInput          `yaml:"kindsys_composable"`
	Cue               *CueInput          `yaml:"cue"`
}

func (*Input) InterpolateParameters

func (input *Input) InterpolateParameters(interpolator ParametersInterpolator) error

func (*Input) LoadSchemas

func (input *Input) LoadSchemas(ctx context.Context) (ast.Schemas, error)

type InputBase

type InputBase struct {
	// AllowedObjects is a list of object names that will be allowed when
	// parsing the input schema.
	// Note: if AllowedObjects is empty, no filter is applied.
	AllowedObjects []string `yaml:"allowed_objects"`

	// Transforms holds a list of paths to files containing compiler passes
	// to apply to the input.
	Transforms []string `yaml:"transformations"`

	// Metadata to add to the schema, this can be used to set Kind and Variant
	Metadata *ast.SchemaMeta `yaml:"metadata"`
}

InputBase provides common options and behavior, meant to be re-used across all input types.

type JSONSchemaInput

type JSONSchemaInput struct {
	InputBase `yaml:",inline"`

	// Path to a JSONSchema file.
	Path string `yaml:"path"`

	// URL to a JSONSchema file.
	URL string `yaml:"url"`

	// Package name to use for the input schema. If empty, it will be guessed
	// from the input file name.
	Package string `yaml:"package"`
}

func (*JSONSchemaInput) LoadSchemas

func (input *JSONSchemaInput) LoadSchemas(ctx context.Context) (ast.Schemas, error)

type KindRegistryInput

type KindRegistryInput struct {
	InputBase `yaml:",inline"`

	Path    string `yaml:"path"`
	Version string `yaml:"version"`
}

func (*KindRegistryInput) LoadSchemas

func (input *KindRegistryInput) LoadSchemas(_ context.Context) (ast.Schemas, error)

type OpenAPIInput

type OpenAPIInput struct {
	InputBase `yaml:",inline"`

	// Path to an OpenAPI file.
	Path string `yaml:"path"`

	// URL to an OpenAPI file.
	URL string `yaml:"url"`

	// Package name to use for the input schema. If empty, it will be guessed
	// from the input file name.
	Package string `yaml:"package"`

	// NoValidate disables validation of the OpenAPI spec.
	NoValidate bool `yaml:"no_validate"`
}

func (*OpenAPIInput) LoadSchemas

func (input *OpenAPIInput) LoadSchemas(ctx context.Context) (ast.Schemas, error)

type Output

type Output struct {
	Directory string `yaml:"directory"`

	Types      bool `yaml:"types"`
	Builders   bool `yaml:"builders"`
	Converters bool `yaml:"converters"`

	Languages []*OutputLanguage `yaml:"languages"`

	// PackageTemplates is the path to a directory containing "package templates".
	// These templates are used to add arbitrary files to the generated code, with
	// the goal of turning it into a fully-fledged package.
	// Templates in that directory are expected to be organized by language:
	// “`
	// package_templates
	// ├── go
	// │   ├── LICENSE.md
	// │   └── README.md
	// └── typescript
	//     ├── babel.config.json
	//     ├── package.json
	//     ├── README.md
	//     └── tsconfig.json
	// “`
	PackageTemplates string `yaml:"package_templates"`

	// RepositoryTemplates is the path to a directory containing
	// "repository-level templates".
	// These templates are used to add arbitrary files to the repository, such as CI pipelines.
	//
	// Templates in that directory are expected to be organized by language:
	// “`
	// repository_templates
	// ├── go
	// │   └── .github
	// │   	   └── workflows
	// │   	       └── go-ci.yaml
	// └── typescript
	//     └── .github
	//     	   └── workflows
	//     	       └── typescript-ci.yaml
	// “`
	RepositoryTemplates string `yaml:"repository_templates"`

	// TemplatesData holds data that will be injected into package and
	// repository templates when rendering them.
	TemplatesData map[string]string `yaml:"templates_data"`
}

type OutputLanguage

type OutputLanguage struct {
	Go         *golang.Config     `yaml:"go"`
	Java       *java.Config       `yaml:"java"`
	JSONSchema *jsonschema.Config `yaml:"jsonschema"`
	OpenAPI    *openapi.Config    `yaml:"openapi"`
	PHP        *php.Config        `yaml:"php"`
	Python     *python.Config     `yaml:"python"`
	Terraform  *terraform.Config  `yaml:"terraform"`
	Typescript *typescript.Config `yaml:"typescript"`
}

type ParametersInterpolator

type ParametersInterpolator func(input string) string

type Pipeline

type Pipeline struct {
	Debug bool `yaml:"debug"`

	Inputs     []*Input   `yaml:"inputs"`
	Transforms Transforms `yaml:"transformations"`
	Output     Output     `yaml:"output"`

	Parameters map[string]string `yaml:"parameters"`
	// contains filtered or unexported fields
}

func NewPipeline

func NewPipeline() (*Pipeline, error)

func PipelineFromFile

func PipelineFromFile(file string, opts ...PipelineOption) (*Pipeline, error)

func (*Pipeline) LoadSchemas

func (pipeline *Pipeline) LoadSchemas(ctx context.Context) (ast.Schemas, error)

func (*Pipeline) Run

func (pipeline *Pipeline) Run(ctx context.Context) (*codejen.FS, error)

type PipelineOption

type PipelineOption func(pipeline *Pipeline)

func Parameters

func Parameters(extraParameters map[string]string) PipelineOption

func Reporter

func Reporter(reporter ProgressReporter) PipelineOption

type ProgressReporter

type ProgressReporter func(msg string)

type Transforms

type Transforms struct {
	// CommonPassesFiles holds a list of paths to files containing compiler
	// passes to apply to all the schemas.
	// Note: these compiler passes are applied *before* language-specific passes.
	CommonPassesFiles []string `yaml:"schemas"`

	// CommonPasses holds a list of compiler passes to apply to all the schemas.
	// If this field is set, CommonPassesFiles is ignored.
	// Note: these compiler passes are applied *before* language-specific passes.
	CommonPasses compiler.Passes `yaml:"-"`

	// FinalPasses holds a list of compiler passes to apply to all the schemas.
	// Note: these compiler passes are applied *after* language-specific passes.
	FinalPasses compiler.Passes `yaml:"-"`

	// VeneersDirectories holds a list of paths to directories containing
	// veneers to apply to all the builders.
	VeneersDirectories []string `yaml:"builders"`
}

Jump to

Keyboard shortcuts

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