utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddEntryToOASYAML

func AddEntryToOASYAML(oas *yaml.Node, key string, value any, defaultVal *yaml.Node) (*yaml.Node, error)

func ApplyOASOverlay

func ApplyOASOverlay(overlayNode *yaml.Node, specNode *yaml.Node, overlayFile string, specFile string) (*yaml.Node, error)

func ApplyOASOverlayAction

func ApplyOASOverlayAction(action *yaml.Node, specNode *yaml.Node, overlayFile string, specFile string) (*yaml.Node, error)

func CopyDir added in v1.1.0

func CopyDir(dest string, src string) error

func CopyFile

func CopyFile(dest string, src string) error

func GetDocMapRoot

func GetDocMapRoot(yamlNode *yaml.Node) *yaml.Node

func GetFieldOrCreateNew

func GetFieldOrCreateNew(node *yaml.Node, key string, value *yaml.Node) *yaml.Node

func HandleTestPanic added in v1.1.0

func HandleTestPanic(t *testing.T)

func JSONFile2YAMLFile

func JSONFile2YAMLFile(input string, output string) error

func JSONFileToTFFile added in v1.1.0

func JSONFileToTFFile(input string, output string) error

JSONFileToTFFile reads a Terraform JSON file (.tf.json), converts it to HCL text, and writes it.

func JSONPointer2JSONPath

func JSONPointer2JSONPath(jsonPointer string) (jsonPath string, err error)

func JSONText2YAMLText

func JSONText2YAMLText(reader io.Reader) ([]byte, error)

func JSONTextToTFText added in v1.1.0

func JSONTextToTFText(jsonBytes []byte, fileName string) ([]byte, error)

JSONTextToTFText converts Terraform JSON text bytes into formatted Terraform HCL text bytes.

func LocateRef

func LocateRef(refFileNode *yaml.Node, refJSONPath string, jsonRef string) (*yaml.Node, error)

func MakeCyclicRefPlaceholder

func MakeCyclicRefPlaceholder(refJSONPath string) *yaml.Node

func MapToTFText added in v1.1.0

func MapToTFText(data map[string]any, fileName string) ([]byte, error)

MapToTFText converts a map[string]any into a formatted Terraform HCL text byte slice.

func Must

func Must(err error)

func MustClose

func MustClose(c io.Closer)

func MustReadFileBytes

func MustReadFileBytes(path string) []byte

func MustRemoveAll added in v1.1.0

func MustRemoveAll(path string)

func NewCyclicJSONRefError

func NewCyclicJSONRefError(paths []string) error

func NewMapNode

func NewMapNode() *yaml.Node

func NewRefNode

func NewRefNode(refJSONPath string) *yaml.Node

func NewStringNode

func NewStringNode(value string, style yaml.Style) *yaml.Node

func OAS2FileToOAS3File

func OAS2FileToOAS3File(input string, output string, allowCycles bool) error

func OAS2YAMLtoOAS3YAML

func OAS2YAMLtoOAS3YAML(oasNode *yaml.Node) (*yaml.Node, error)

func OAS3ToYAML

func OAS3ToYAML(doc *openapi3.T) (*yaml.Node, error)

func OASOverlay

func OASOverlay(overlayFile string, specFile string, outputFile string) error

func PushDir

func PushDir(dir string) func()

func ReadInputText

func ReadInputText(input string) ([]byte, error)

func ReadInputTextFile

func ReadInputTextFile(input string) ([]byte, error)

func RemoveExtensions

func RemoveExtensions(input string, output string) error

func RemoveOASExtensions

func RemoveOASExtensions(root *yaml.Node) (*yaml.Node, error)

func RemoveOASExtensionsRecursive

func RemoveOASExtensionsRecursive(node *yaml.Node, parentField string) (*yaml.Node, error)

func RemoveOASSchemaExtensions added in v1.1.1

func RemoveOASSchemaExtensions(root *yaml.Node) (*yaml.Node, error)

func RemoveSchemaExtensions added in v1.1.1

func RemoveSchemaExtensions(input string, output string) error

func RemoveYAMLComments

func RemoveYAMLComments(data []byte) []byte

func RequireBundleZipEquals

func RequireBundleZipEquals(t *testing.T, expectedBundleZip string, actualBundleZip string)

func ResolveDollarRefs

func ResolveDollarRefs(input string, output string, allowCycles bool) error

func Run added in v1.1.0

func Run(name string, arg ...string) (string, error)

func RunNPMTTest added in v1.1.0

func RunNPMTTest(t *testing.T, targetDir string)

RunNPMTTest checks for 'npm' and 'node' in PATH and skips the test if either is not found. If available, it changes the working directory to targetDir, runs 'npm install', and then executes 'npm run unit-test', streaming the output directly.

func RunT added in v1.1.0

func RunT(cmd *exec.Cmd, t *testing.T)

func SplitJSONRef

func SplitJSONRef(refStr string) (location string, jsonPath string, err error)

func Struct2XMLDocText

func Struct2XMLDocText(p any) ([]byte, error)

func TFFileToJSONFile added in v1.1.0

func TFFileToJSONFile(input string, output string) error

TFFileToJSONFile converts a Terraform HCL file (.tf) to a JSON file.

func TFFileToMap added in v1.1.0

func TFFileToMap(f *hcl.File, fileName string) (map[string]any, error)

TFFileToMap converts a parsed Terraform hcl.File into a generic map[string]interface{}.

func TFText2HCLFile added in v1.1.0

func TFText2HCLFile(fileText string, filePath string) (*hcl.File, error)

func TFTextToJSONText added in v1.1.0

func TFTextToJSONText(text []byte, fileName string) ([]byte, error)

TFTextToJSONText converts Terraform HCL text bytes to Terraform JSON text bytes.

func TFTextToMap added in v1.1.0

func TFTextToMap(text []byte, fileName string) (map[string]any, error)

TFTextToMap converts Terraform HCL text bytes to a Go map[string]any.

func Text2XML

func Text2XML(reader io.Reader) (*etree.Document, error)

func Text2YAML

func Text2YAML(reader io.Reader) (*yaml.Node, error)

func ToV3

func ToV3(doc2 *openapi2.T) (*openapi3.T, error)

func UnFlowYAMLNode

func UnFlowYAMLNode(node *yaml.Node) *yaml.Node

func WriteOutputText

func WriteOutputText(output string, outputText []byte) error

func XML2Text

func XML2Text(doc *etree.Document) ([]byte, error)

func XML2YAML

func XML2YAML(doc *etree.Document) (*yaml.Node, error)

func XML2YAMLRecursive

func XML2YAMLRecursive(ele *etree.Element) (key *yaml.Node, value *yaml.Node, err error)

func XML2YAMLText

func XML2YAMLText(doc *etree.Document, indent int) ([]byte, error)

func XMLFile2YAMLFile

func XMLFile2YAMLFile(input string, output string) error

func XMLText2XML

func XMLText2XML(reader io.Reader) (*etree.Document, error)

func XMLText2YAML

func XMLText2YAML(reader io.Reader) (*yaml.Node, error)

func XMLText2YAMLText

func XMLText2YAMLText(reader io.Reader) ([]byte, error)

func XMLTextFormat

func XMLTextFormat(reader io.Reader) ([]byte, error)

func YAML2Text

func YAML2Text(node *yaml.Node, indent int) ([]byte, error)

func YAML2XML

func YAML2XML(node *yaml.Node) (*etree.Document, error)

func YAML2XMLRecursive

func YAML2XMLRecursive(node *yaml.Node, parent *etree.Element) (*etree.Element, error)

func YAML2XMLText

func YAML2XMLText(node *yaml.Node) ([]byte, error)

func YAMLDetectRefCycles

func YAMLDetectRefCycles(root *yaml.Node, filePath string) (cycles [][]string, err error)

func YAMLDetectRefCyclesRecursive

func YAMLDetectRefCyclesRecursive(node *yaml.Node, relParentPath string, parentFile string, activePaths []string, loaded *map[string]*yaml.Node, cycles *[][]string) error

func YAMLDoc2File

func YAMLDoc2File(docNode *yaml.Node, outputFile string) error

func YAMLFile2JSONFile

func YAMLFile2JSONFile(input string, output string) error

func YAMLFile2XMLFile

func YAMLFile2XMLFile(input string, output string) error

func YAMLFile2YAML

func YAMLFile2YAML(filePath string) (*yaml.Node, error)

func YAMLResolveAllRefs added in v1.1.0

func YAMLResolveAllRefs(root *yaml.Node, filePath string, allowCycles bool) (*yaml.Node, error)

func YAMLResolveRefs

func YAMLResolveRefs(root *yaml.Node, filePath string, allowCycles bool) (*yaml.Node, error)

func YAMLResolveRefsRecursive

func YAMLResolveRefsRecursive(node *yaml.Node, relParentPath string, parentFile string, activePaths []string, loaded *map[string]*yaml.Node, cycles *[][]string, resolveMainRefs bool) (*yaml.Node, error)

func YAMLText2JSONText

func YAMLText2JSONText(reader io.Reader) ([]byte, error)

func YAMLText2XML

func YAMLText2XML(reader io.Reader) (*etree.Document, error)

func YAMLText2XMLText

func YAMLText2XMLText(reader io.Reader) ([]byte, error)

Types

type CyclicJSONRefError

type CyclicJSONRefError struct {
	Paths []string
}

func (CyclicJSONRefError) Error

func (e CyclicJSONRefError) Error() string

type MultiError

type MultiError struct {
	Errors []error
}

func (MultiError) Error

func (e MultiError) Error() string

type StdoutCapture

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

func NewStdoutCapture

func NewStdoutCapture() (*StdoutCapture, error)

func (*StdoutCapture) Read

func (sf *StdoutCapture) Read() ([]byte, error)

func (*StdoutCapture) Restore

func (sf *StdoutCapture) Restore()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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