generator

package
v5.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapPathOperations

func MapPathOperations(p *openapi3.PathItem) map[string]*openapi3.Operation

MapPathOperations returns a mapping from HTTP method to *openapi3.Operation for a given *openapi3.PathItem.

func NewMap

func NewMap(generatorsConf config.Generators, options ...Option) (map[string]*Generator, error)

NewMap instanstiates a map of Generators from configuration.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates files for new resources from data models and templates.

func New

func New(conf *config.Generator, options ...Option) (*Generator, error)

New returns a new Generator from configuration.

func (*Generator) Execute

func (g *Generator) Execute(resources ResourceMap) ([]string, error)

Execute runs the generator on the given resources.

func (*Generator) Scope

func (g *Generator) Scope() config.GeneratorScope

Scope returns the configured scope type of the generator.

type OperationMap

type OperationMap map[string][]OperationVersion

OperationMap defines a mapping from operation name to all versions of that operation within a resource.

func MapResourceOperations

func MapResourceOperations(resourceVersions *vervet.ResourceVersions) (OperationMap, error)

MapResourceOperations returns a mapping from operation ID to all versions of that operation.

type OperationVersion

type OperationVersion struct {
	*vervet.ResourceVersion
	Path      string
	Method    string
	Operation *openapi3.Operation
}

OperationVersion represents a version of an operation within a collection of resource versions.

type Option

type Option func(g *Generator)

Option configures a Generator.

func Debug

func Debug(debug bool) Option

Debug turns on template debug logging.

func DryRun

func DryRun(dryRun bool) Option

DryRun executes templates and lists the files that would be generated without actually generating them.

func Filesystem

func Filesystem(FS fs.FS) Option

Filesystem sets the filesytem that the generator checks for templates.

func Force

func Force(force bool) Option

Force configures the Generator to overwrite generated artifacts.

func Functions

func Functions(funcs template.FuncMap) Option

func Here

func Here(here string) Option

Here sets the .Here scope property. This is typically relative to the location of the generators config file.

type ResourceKey

type ResourceKey struct {
	API      string
	Resource string
	Path     string
}

ResourceKey uniquely identifies an API resource.

type ResourceMap

type ResourceMap map[ResourceKey]*vervet.ResourceVersions

ResourceMap defines a mapping from API resource identity to its versions.

func MapResources

func MapResources(proj *config.Project) (ResourceMap, error)

MapResources returns a mapping of all resources managed within a Vervet project.

type ResourceScope

type ResourceScope struct {
	// ResourceVersions contains all the versions of this resource.
	*vervet.ResourceVersions
	// API is name of the API containing this resource.
	API string
	// Path is the path to the resource directory.
	Path string
	// Here is the directory containing the executing template.
	Here string
	// Env is a map of template values read from the os environment.
	Env map[string]string
}

ResourceScope identifies a resource that the generator is building for.

func (*ResourceScope) Resource

func (s *ResourceScope) Resource() string

Resource returns the name of the resource in scope.

type VersionScope

type VersionScope struct {
	*vervet.ResourceVersion
	// API is name of the API containing this resource.
	API string
	// Path is the path to the resource directory.
	Path string
	// Here is the directory containing the generator template.
	Here string
	// Env is a map of template values read from the os environment.
	Env map[string]string
}

VersionScope identifies a distinct version of a resource that the generator is building for.

func (*VersionScope) Resource

func (s *VersionScope) Resource() string

Resource returns the name of the resource in scope.

func (*VersionScope) Version

func (s *VersionScope) Version() *vervet.Version

Version returns the version of the resource in scope.

Jump to

Keyboard shortcuts

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