converter

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultModelPathSeparator = "|"
	ArrayFieldMarker          = "[]"
	AllMapKeysFieldMarker     = "*"
)

Variables

This section is empty.

Functions

func BuildArrayField added in v1.3.1

func BuildArrayField(field string) string

func BuildDefaultModelPath added in v1.3.1

func BuildDefaultModelPath(paths ...string) string

func BuildModelPath added in v1.3.1

func BuildModelPath(modelPathSeparator string, paths ...string) string

Types

type APIModel

type APIModel interface {
	MarshalBinary() ([]byte, error)
	UnmarshalBinary(b []byte) error
}

type ArrIndexer

type ArrIndexer struct {
	IndicesInts []int
}

func (*ArrIndexer) AppendIndex

func (arrIndex *ArrIndexer) AppendIndex(index int)

func (*ArrIndexer) GetAllIndexes

func (arrIndex *ArrIndexer) GetAllIndexes() []int

func (*ArrIndexer) IncrementLastIndex

func (arrIndex *ArrIndexer) IncrementLastIndex()

func (*ArrIndexer) IsActive

func (arrIndex *ArrIndexer) IsActive() bool

func (*ArrIndexer) New

func (arrIndex *ArrIndexer) New()

func (*ArrIndexer) RemoveLastIndex

func (arrIndex *ArrIndexer) RemoveLastIndex()

type BlockSliceToStructSlice

type BlockSliceToStructSlice []*BlockToStruct

BlockSliceToStructSlice Converts a Terraform Block Slice to a Slice of Swagger Structs (N:N).

type BlockToStruct

type BlockToStruct map[string]interface{}

BlockToStruct Converts a Terraform Block to a Swagger Struct (1:1).

func (*BlockToStruct) UnpackSchema

func (b *BlockToStruct) UnpackSchema(modelPathSeparator string, mapValue interface{}, prefix string) interface{}

UnpackSchema Unpacks a schema to a higher level schema, useful for data sources which list an individual Swagger API Model.

type BlockToStructSlice

type BlockToStructSlice []*BlockToStruct

BlockToStructSlice Converts a Terraform Block to a Slice of Swagger Structs (1:N).

type EvaluatedField

type EvaluatedField struct {
	Field    string
	EvalFunc EvaluationFunc
}

EvaluatedField If needed to intervene in specific fields, this helps you connect a function to the converter.

type EvaluationFunc

type EvaluationFunc func(EvaluationMode, interface{}) interface{}

type EvaluationMode

type EvaluationMode string
const (
	ConstructModel    EvaluationMode = "CONSTRUCT_MODEL"
	ConstructTFSchema EvaluationMode = "CONSTRUCT_TF_SCHEMA"
)

type ListToStruct

type ListToStruct []string

ListToStruct Converts a Terraform primitive Slice field to a Slice of Swagger Structs (1:N).

type Map

type Map map[string]interface{}

Map Converts a Terraform Block/Map to Swagger Struct/Map.

func (*Map) Copy

func (curMap *Map) Copy(excludedKeys []string) Map

Copy Creates a copy of a Map object. excludeKeys argument can be used to exclude certain keys to be copied.

type TFSchemaModelConverter

type TFSchemaModelConverter[T APIModel] struct {
	TFModelMap         *BlockToStruct
	ModelPathSeparator string
}

func (*TFSchemaModelConverter[T]) ConvertTFSchemaToAPIModel

func (converter *TFSchemaModelConverter[T]) ConvertTFSchemaToAPIModel(data *schema.ResourceData, buildOnlyKeys []string) (modelPtr T, err error)

ConvertTFSchemaToAPIModel This function converts a given TF Schema data (aka schema.ResourceData) to Swagger API Model. Arguments for the function are: data - a schema.ResourceData object. buildOnlyKeys - a []string for specifying specific keys to be built in the model. keys should be supplied relatively to the Terraform schema structure, for nested keys it should be supplied with a separator. If no keys supplied in the slice, the function will build the entire model.

func (*TFSchemaModelConverter[T]) FillTFSchema

func (converter *TFSchemaModelConverter[T]) FillTFSchema(modelPtr T, data *schema.ResourceData) error

FillTFSchema This function converts a given Swagger API Model to TF Schema data (aka schema.ResourceData) structure and fills the schema. Arguments for the function are: modelPtr - a Swagger API Model object. data - a schema.ResourceData object.

func (*TFSchemaModelConverter[T]) UnpackSchema

func (converter *TFSchemaModelConverter[T]) UnpackSchema(prefix string) *BlockToStruct

UnpackSchema This function helps you create a higher level Schema. It utilizes the implementation of schema unpacking implemented for BlockToStruct types. As an example, if you have converter or converter mapping of an object like Target Location and you need to create another schema for a slice of Target Locations, then you can use the converter or the mapping to unpack the schema for the higher level struct containing the list of Target Locations.

Jump to

Keyboard shortcuts

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