defaulting

package
v0.0.0-...-d88c8b5 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default(x interface{}, s *structuralschema.Structural)

Default does defaulting of x depending on default values in s. Default values from s are deep-copied.

func PruneDefaults

func PruneDefaults(s *structuralschema.Structural) error

PruneDefaults prunes default values according to the schema and according to the ObjectMeta definition of the running server. It mutates the passed schema.

func ValidateDefaults

func ValidateDefaults(pth *field.Path, s *structuralschema.Structural, isResourceRoot, requirePrunedDefaults bool) (field.ErrorList, error)

ValidateDefaults checks that default values validate and are properly pruned.

Types

type AccessorFunc

type AccessorFunc func(obj map[string]interface{}) (x interface{}, found bool, err error)

AccessorFunc returns a node x in obj on a fixed (implicitly encoded) JSON path if that path exists in obj (found==true). If it does not exist, found is false. If on the path the type of a field is wrong, an error is returned.

type SurroundingObjectFunc

type SurroundingObjectFunc func(focus interface{}) (map[string]interface{}, AccessorFunc, error)

SurroundingObjectFunc is a surrounding object builder with a given x at a leaf. Which leave is determined by the series of Index() and Child(k) calls. It also returns the inverse of the builder, namely the accessor that extracts x from the test object.

With obj, acc, _ := someSurroundingObjectFunc(x) we get:

acc(obj) == x
reflect.DeepEqual(acc(DeepCopy(obj), x) == x

where x is the original instance for slices and maps.

If after computation of acc the node holding x in obj is mutated (e.g. pruned), the accessor will return that mutated node value (e.g. the pruned x).

Example (ignoring the last two return values):

NewRootObjectFunc()(x) == x
NewRootObjectFunc().Index()(x) == [x]
NewRootObjectFunc().Index().Child("foo") == [{"foo": x}]
NewRootObjectFunc().Index().Child("foo").Child("bar") == [{"foo": {"bar":x}}]
NewRootObjectFunc().Index().Child("foo").Child("bar").Index() == [{"foo": {"bar":[x]}}]

and:

NewRootObjectFunc(), then acc(x) == x
NewRootObjectFunc().Index(), then acc([x]) == x
NewRootObjectFunc().Index().Child("foo"), then acc([{"foo": x}]) == x
NewRootObjectFunc().Index().Child("foo").Child("bar"), then acc([{"foo": {"bar":x}}]) == x
NewRootObjectFunc().Index().Child("foo").Child("bar").Index(), then acc([{"foo": {"bar":[x]}}]) == x

func NewRootObjectFunc

func NewRootObjectFunc() SurroundingObjectFunc

NewRootObjectFunc returns the identity function. The passed focus value must be an object.

func (SurroundingObjectFunc) Child

Child returns a function x => f({k: x}) and the corresponding accessor.

func (SurroundingObjectFunc) Index

Index returns a function x => f([x]) and the corresponding accessor.

func (SurroundingObjectFunc) WithTypeMeta

WithTypeMeta returns a closure with the TypeMeta fields set if they are defined. This mutates f(x).

Jump to

Keyboard shortcuts

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