yamlconfig

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const EndpointToken = "@endpoint:"

Variables

View Source
var Functions = template.FuncMap{
	"toGoName":              ToGoName,
	"camelCase":             CamelCase,
	"snakeCase":             SnakeCase,
	"sprintf":               fmt.Sprintf,
	"errorf":                Errorf,
	"toLower":               strings.ToLower,
	"path":                  BuildPath,
	"hasId":                 HasId,
	"getId":                 GetId,
	"hasReference":          HasReference,
	"isListSet":             IsListSet,
	"isList":                IsList,
	"isSet":                 IsSet,
	"isStringListSet":       IsStringListSet,
	"isInt64ListSet":        IsInt64ListSet,
	"isNestedListSet":       IsNestedListSet,
	"isNestedListSetMap":    IsNestedListSetMap,
	"isNestedList":          IsNestedList,
	"isNestedSet":           IsNestedSet,
	"isNestedMap":           IsNestedMap,
	"importParts":           ImportParts,
	"subtract":              Subtract,
	"iterate":               Iterate,
	"getImportExcludes":     GetImportExcludes,
	"getFullModelName":      GetFullModelName,
	"hasComputedAttributes": HasComputedAttributes,
	"buildTestPath":         BuildTestPath,
}

Map of templating functions

Functions

func BuildPath

func BuildPath(s []string) string

Templating helper function to build a SJSON path

func BuildTestPath added in v0.1.4

func BuildTestPath(attr ...YamlConfigAttribute) string

Templating helper function to build a test path

func CamelCase

func CamelCase(s string) string

Templating helper function to convert string to camel case

func CamelToSnake

func CamelToSnake(str string) string

func Errorf

func Errorf(s string, args ...any) (struct{}, error)

Templating helper function to fail a template mid-way

func GetFullModelName added in v0.1.2

func GetFullModelName(attr YamlConfigAttribute) string

GetFullModelName returns the full model name for an attribute, including data path

func GetImportExcludes

func GetImportExcludes(attributes []YamlConfigAttribute) []string

GetImportExcludes returns a list of attributes to exclude from import testing

func HasComputedAttributes added in v0.1.4

func HasComputedAttributes(attributes []YamlConfigAttribute) bool

HasComputedAttributes returns true if any attributes are computed

func HasId

func HasId(attributes []YamlConfigAttribute) bool

Templating helper function to return true if id included in attributes

func HasReference

func HasReference(attributes []YamlConfigAttribute) bool

Templating helper function to return true if reference included in attributes

func ImportParts

func ImportParts(config YamlConfig) int

Templating helper function to return number of import parts

func IsInt64ListSet

func IsInt64ListSet(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list or set of integers without nested elements

func IsList

func IsList(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list without nested elements

func IsListSet

func IsListSet(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list or set without nested elements

func IsNestedList

func IsNestedList(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list with nested elements

func IsNestedListSet

func IsNestedListSet(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list or set with nested elements

func IsNestedListSetMap added in v0.1.4

func IsNestedListSetMap(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list, set or map with nested elements

func IsNestedMap added in v0.1.4

func IsNestedMap(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a map with nested elements

func IsNestedSet

func IsNestedSet(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a set with nested elements

func IsSet

func IsSet(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a set without nested elements

func IsStringListSet

func IsStringListSet(attribute YamlConfigAttribute) bool

Templating helper function to return true if type is a list or set of strings without nested elements

func Iterate

func Iterate(count int) []int

Templating helper function to iterate over a count

func MergeYamlConfigAttributes

func MergeYamlConfigAttributes(existing *[]YamlConfigAttributeP, new *[]YamlConfigAttributeP) *[]YamlConfigAttributeP

func P

func P[T any](v T) *T

func SnakeCase

func SnakeCase(s string) string

Templating helper function to convert string to snake case

func Subtract

func Subtract(a, b int) int

Templating helper function to subtract one number from another

func ToGoName

func ToGoName(s string) string

Templating helper function to convert TF name to GO name

Types

type YamlConfig

type YamlConfig struct {
	Name                string                `yaml:"name,omitempty"`
	TfName              string                `yaml:"tf_name,omitempty"`
	BulkName            string                `yaml:"bulk_name,omitempty"`
	SpecEndpoint        string                `yaml:"spec_endpoint,omitempty"`
	RestEndpoint        string                `yaml:"rest_endpoint,omitempty"`
	NoDataSource        bool                  `yaml:"no_data_source,omitempty"`
	NoResource          bool                  `yaml:"no_resource,omitempty"`
	BulkDataSource      bool                  `yaml:"bulk_data_source,omitempty"`
	PutCreate           bool                  `yaml:"put_create,omitempty"`
	GetFromAll          bool                  `yaml:"get_from_all,omitempty"`
	NoUpdate            bool                  `yaml:"no_update,omitempty"`
	NoDelete            bool                  `yaml:"no_delete,omitempty"`
	NoImport            bool                  `yaml:"no_import,omitempty"`
	NoRead              bool                  `yaml:"no_read,omitempty"`
	IdName              string                `yaml:"id_name,omitempty"`
	EarlyAccess         bool                  `yaml:"early_access,omitempty"`
	DataSourceNameQuery bool                  `yaml:"data_source_name_query,omitempty"`
	MinimumVersion      string                `yaml:"minimum_version,omitempty"`
	DsDescription       string                `yaml:"ds_description,omitempty"`
	ResDescription      string                `yaml:"res_description,omitempty"`
	DocCategory         string                `yaml:"doc_category,omitempty"`
	ExcludeTest         bool                  `yaml:"exclude_test,omitempty"`
	SkipMinimumTest     bool                  `yaml:"skip_minimum_test,omitempty"`
	TestTags            []string              `yaml:"test_tags,omitempty,flow"`
	TestVariables       []string              `yaml:"test_variables,omitempty,flow"`
	IgnoreAttributes    []string              `yaml:"ignore_attributes,omitempty,flow"`
	Attributes          []YamlConfigAttribute `yaml:"attributes,omitempty"`
	TestPrerequisites   string                `yaml:"test_prerequisites,omitempty"`
}

func NewYamlConfig added in v0.1.1

func NewYamlConfig(bytes []byte) (YamlConfig, error)

type YamlConfigAttribute

type YamlConfigAttribute struct {
	ModelName          string                `yaml:"model_name,omitempty"`
	TfName             string                `yaml:"tf_name,omitempty"`
	Type               string                `yaml:"type,omitempty"`
	ElementType        string                `yaml:"element_type,omitempty"`
	DataPath           []string              `yaml:"data_path,omitempty,flow"`
	Id                 bool                  `yaml:"id,omitempty"`
	Reference          bool                  `yaml:"reference,omitempty"`
	RequiresReplace    bool                  `yaml:"requires_replace,omitempty"`
	Mandatory          bool                  `yaml:"mandatory,omitempty"`
	WriteOnly          bool                  `yaml:"write_only,omitempty"`
	WriteChangesOnly   bool                  `yaml:"write_changes_only,omitempty"`
	ExcludeTest        bool                  `yaml:"exclude_test,omitempty"`
	ExcludeExample     bool                  `yaml:"exclude_example,omitempty"`
	AllowImportChanges bool                  `yaml:"allow_import_changes,omitempty"`
	Description        string                `yaml:"description,omitempty"`
	Example            string                `yaml:"example,omitempty"`
	MapKeyExample      string                `yaml:"map_key_example,omitempty"`
	EnumValues         []string              `yaml:"enum_values,omitempty,flow"`
	MinList            int64                 `yaml:"min_list,omitempty"`
	MaxList            int64                 `yaml:"max_list,omitempty"`
	MinInt             int64                 `yaml:"min_int,omitempty"`
	MaxInt             int64                 `yaml:"max_int,omitempty"`
	MinFloat           float64               `yaml:"min_float,omitempty"`
	MaxFloat           float64               `yaml:"max_float,omitempty"`
	OrderedList        bool                  `yaml:"ordered_list,omitempty"`
	StringPatterns     []string              `yaml:"string_patterns,omitempty,flow"`
	StringMinLength    int64                 `yaml:"string_min_length,omitempty"`
	StringMaxLength    int64                 `yaml:"string_max_length,omitempty"`
	Computed           bool                  `yaml:"computed,omitempty"`
	DefaultValue       string                `yaml:"default_value,omitempty"`
	Value              string                `yaml:"value,omitempty"`
	TestValue          string                `yaml:"test_value,omitempty"`
	MinimumTestValue   string                `yaml:"minimum_test_value,omitempty"`
	TestTags           []string              `yaml:"test_tags,omitempty,flow"`
	Attributes         []YamlConfigAttribute `yaml:"attributes,omitempty"`
	GoTypeName         string                `yaml:"gotypename,omitempty"`
	GoTypeBulkName     string                `yaml:"gobulktypename,omitempty"`
}

func GetId

func GetId(attributes []YamlConfigAttribute) YamlConfigAttribute

Templating helper function to return the id

func (*YamlConfigAttribute) Init

func (attr *YamlConfigAttribute) Init(parentGoTypeName, parentGoTypeBulkName string) error

type YamlConfigAttributeP

type YamlConfigAttributeP struct {
	ModelName          *string                 `yaml:"model_name,omitempty"`
	TfName             *string                 `yaml:"tf_name,omitempty"`
	Type               *string                 `yaml:"type,omitempty"`
	ElementType        *string                 `yaml:"element_type,omitempty"`
	DataPath           *[]string               `yaml:"data_path,omitempty,flow"`
	Id                 *bool                   `yaml:"id,omitempty"`
	Reference          *bool                   `yaml:"reference,omitempty"`
	RequiresReplace    *bool                   `yaml:"requires_replace,omitempty"`
	Mandatory          *bool                   `yaml:"mandatory,omitempty"`
	WriteOnly          *bool                   `yaml:"write_only,omitempty"`
	WriteChangesOnly   *bool                   `yaml:"write_changes_only,omitempty"`
	ExcludeTest        *bool                   `yaml:"exclude_test,omitempty"`
	ExcludeExample     *bool                   `yaml:"exclude_example,omitempty"`
	AllowImportChanges *bool                   `yaml:"allow_import_changes,omitempty"`
	Description        *string                 `yaml:"description,omitempty"`
	Example            *string                 `yaml:"example,omitempty"`
	MapKeyExample      *string                 `yaml:"map_key_example,omitempty"`
	EnumValues         *[]string               `yaml:"enum_values,omitempty,flow"`
	MinList            *int64                  `yaml:"min_list,omitempty"`
	MaxList            *int64                  `yaml:"max_list,omitempty"`
	MinInt             *int64                  `yaml:"min_int,omitempty"`
	MaxInt             *int64                  `yaml:"max_int,omitempty"`
	MinFloat           *float64                `yaml:"min_float,omitempty"`
	MaxFloat           *float64                `yaml:"max_float,omitempty"`
	OrderedList        *bool                   `yaml:"ordered_list,omitempty"`
	StringPatterns     *[]string               `yaml:"string_patterns,omitempty,flow"`
	StringMinLength    *int64                  `yaml:"string_min_length,omitempty"`
	StringMaxLength    *int64                  `yaml:"string_max_length,omitempty"`
	Computed           *bool                   `yaml:"computed,omitempty"`
	DefaultValue       *string                 `yaml:"default_value,omitempty"`
	Value              *string                 `yaml:"value,omitempty"`
	TestValue          *string                 `yaml:"test_value,omitempty"`
	MinimumTestValue   *string                 `yaml:"minimum_test_value,omitempty"`
	TestTags           *[]string               `yaml:"test_tags,omitempty,flow"`
	Attributes         *[]YamlConfigAttributeP `yaml:"attributes,omitempty"`
	GoTypeName         *string                 `yaml:"gotypename,omitempty"`
	GoTypeBulkName     *string                 `yaml:"gobulktypename,omitempty"`
}

func MergeYamlConfigAttribute

func MergeYamlConfigAttribute(existing *YamlConfigAttributeP, new *YamlConfigAttributeP) *YamlConfigAttributeP

type YamlConfigP

type YamlConfigP struct {
	Name                *string                 `yaml:"name,omitempty"`
	TfName              *string                 `yaml:"tf_name,omitempty"`
	BulkName            *string                 `yaml:"bulk_name,omitempty"`
	SpecEndpoint        *string                 `yaml:"spec_endpoint,omitempty"`
	RestEndpoint        *string                 `yaml:"rest_endpoint,omitempty"`
	NoDataSource        *bool                   `yaml:"no_data_source,omitempty"`
	NoResource          *bool                   `yaml:"no_resource,omitempty"`
	BulkDataSource      *bool                   `yaml:"bulk_data_source,omitempty"`
	PutCreate           *bool                   `yaml:"put_create,omitempty"`
	GetFromAll          *bool                   `yaml:"get_from_all,omitempty"`
	NoUpdate            *bool                   `yaml:"no_update,omitempty"`
	NoDelete            *bool                   `yaml:"no_delete,omitempty"`
	NoImport            *bool                   `yaml:"no_import,omitempty"`
	NoRead              *bool                   `yaml:"no_read,omitempty"`
	IdName              *string                 `yaml:"id_name,omitempty"`
	EarlyAccess         *bool                   `yaml:"early_access,omitempty"`
	DataSourceNameQuery *bool                   `yaml:"data_source_name_query,omitempty"`
	MinimumVersion      *string                 `yaml:"minimum_version,omitempty"`
	DsDescription       *string                 `yaml:"ds_description,omitempty"`
	ResDescription      *string                 `yaml:"res_description,omitempty"`
	DocCategory         *string                 `yaml:"doc_category,omitempty"`
	ExcludeTest         *bool                   `yaml:"exclude_test,omitempty"`
	SkipMinimumTest     *bool                   `yaml:"skip_minimum_test,omitempty"`
	TestTags            *[]string               `yaml:"test_tags,omitempty,flow"`
	TestVariables       *[]string               `yaml:"test_variables,omitempty,flow"`
	IgnoreAttributes    *[]string               `yaml:"ignore_attributes,omitempty,flow"`
	Attributes          *[]YamlConfigAttributeP `yaml:"attributes,omitempty"`
	TestPrerequisites   *string                 `yaml:"test_prerequisites,omitempty"`
}

func MergeYamlConfig

func MergeYamlConfig(existing *YamlConfigP, new *YamlConfigP) *YamlConfigP

Jump to

Keyboard shortcuts

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