utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractExtensionGVKs

func ExtractExtensionGVKs(extensions map[string]interface{}) []schema.GroupVersionKind

func ExtractPathGVKs

func ExtractPathGVKs(path *spec3.Path) []schema.GroupVersionKind

func FindFiles

func FindFiles(args ...string) ([]string, error)

func IsEmptyYamlDocument

func IsEmptyYamlDocument(document Document) bool

IsEmptyYamlDocument checks if a yaml document is empty (contains only comments)

Returns true for comment-only single documents, and strings with multiple documents where all docs are comment-only.

func IsJson

func IsJson(file string) bool

func IsYaml

func IsYaml(file string) bool

func IsYamlOrJson

func IsYamlOrJson(file string) bool

func VisitSchema

func VisitSchema(name string, s *spec.Schema, visitor SchemaVisitor) *spec.Schema

Types

type Document

type Document = []byte

func SplitYamlDocuments

func SplitYamlDocuments(fileBytes Document) ([]Document, error)

type PostorderVisitor

type PostorderVisitor func(ctx VisitingContext, s *spec.Schema) *spec.Schema

func (PostorderVisitor) VisitAfter

func (f PostorderVisitor) VisitAfter(ctx VisitingContext, s **spec.Schema)

func (PostorderVisitor) VisitBefore

func (f PostorderVisitor) VisitBefore(ctx VisitingContext, s **spec.Schema) bool

type PreorderVisitor

type PreorderVisitor func(ctx VisitingContext, s *spec.Schema) (*spec.Schema, bool)

There is no "left" or "right" on this tree, so no in-order is necessary

func (PreorderVisitor) VisitAfter

func (f PreorderVisitor) VisitAfter(ctx VisitingContext, s **spec.Schema)

func (PreorderVisitor) VisitBefore

func (f PreorderVisitor) VisitBefore(ctx VisitingContext, s **spec.Schema) bool

type SchemaVisitor

type SchemaVisitor interface {
	// Called on a node before its children.
	// Return false to stop exploring this subtree, otherwise return true.
	VisitBefore(ctx VisitingContext, s **spec.Schema) bool

	// Called on a node after its children.
	VisitAfter(ctx VisitingContext, s **spec.Schema)
}

type VisitingContext

type VisitingContext struct {
	// What field of the parent context was traversed to find the current
	// schema
	SchemaField string

	// If ShemaField is a collection, what key is this schema contained within
	// SchemaField
	Key string

	// If ShemaField is a collection, what index is this schema contained within
	// SchemaField
	//
	// Part of a Union with `key` If one is set, the other must be unset
	Index int

	Parent *VisitingContext
}

func (*VisitingContext) WithSubField

func (v *VisitingContext) WithSubField(field, key string) VisitingContext

func (*VisitingContext) WithSubIndex

func (v *VisitingContext) WithSubIndex(field string, idx int) VisitingContext

Jump to

Keyboard shortcuts

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